C++

57K

Solutions

24K

Contributors

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.

Share tech news, updates, or what's on your mind.

Sign up to Post

cplusplus.jpg
This jovial programmer is Paul Kent.  I just published his new course on C++.  Great job, Paul!

https://www.experts-exchange.com/courses/1401/Programming-for-You-Introduction-to-C.html

Note: This is a paid course.
0
Hello

In C++, what is the most elegant way to check if an argv[i] is an integer? I prefer a short inbuilt check instead of writing a function that does something like traverse the char* and check if each element is a digit.

Any suggestions? thank you
0
So i have a program which filters a file containing "emails" in a single line, i link you to the exercise (it is a pdf) https://training.olinfo.it/#/task/ioit_spam/statement so my problem is that it doesn't accomplish all of the 4 tasks but from my tests (i've created a file with 1000 emails) it should correctly and pass all of its cases. i don't know if it's a problem of the corrector on the site (you need to register to test the program) but i link here the scoring (it should score 100 in theory) it might be a problem of the corrector? https://imgur.com/a/QmeY5 and the source file is this https://pastebin.com/iVPXUjxb
Thanks to everyone answering i hope i've made the question clear, the program works in my machine, it can even scan 10000 emails if i'd want to, infact i've tried filtering a 8mb file containing 1000 emails with 1000 words each.
this is the link for the 1000 emails input file https://drive.google.com/file/d/1f9OWkzZ_i9T8s6BcNIq5hXqBogCR2Dcj/view?usp=sharing
0
I have been trying to pass a string to fetch the node and am successful for string with only single quote (') and only double quotes ("). But am unable to parse it when string contains both singe and double quotes. I have my string in CString as-

CString str=L("H'el"lo");
and all other combinations of these. Can you please tell me how to do in C++, i have seen the examples are in C# but that are not helping me out.

Here's the link for C# Encoding XPath Expressions with both single and double quotes

XmlNode n = doc.SelectSingleNode(“/root/emp[lname=" + str + "]“);
How should i make my str work for string containing both single and double quotes in any order.
0
Constraint: Cannot change from C++03 or C-88.

After some online search, I wrote the following program to see how to run a class non-static member function in a pthread via a static member helper. But I got the wrong answer. According to breakpoints, the DoSomething constructor is called once; yet on the 2nd call to doSomething, the initial values of val1 and val2 are set to 100, 200.0, respectively. Granted, I set the members of an internal struct to those values, but not to the class data members.

So, how did that happen; how do I get the args.retval return value from the pthread to end in 5 + 16 = 21 + a multiple of 100.
// header
class DoSomething
{
public:
	DoSomething(int v1, float v2)
		: val1(v1), val2(v2) {
	retval = val2 - val1;
	}

	float* doSomething(int v1, float v2) 
	{
		val1 += v1;
		val2 += v2;
		retval = val1 + val2;
		return &retval;
	}

	struct v1v2_s
	{
		int v1;
		float v2;
		float retval;
	};

	static
    void* DS_helper(void* args)
	{
		int v1 = ((v1v2_s*)args)->v1;
		float v2 = ((v1v2_s*)args)->v2;
		((v1v2_s*)args)->retval = *((DoSomething*)args)->doSomething(v1, v2);
		return args;
	}

private:
	int val1;
	float val2;
	float retval;
};

Open in new window

#include "DoSomething.h"

int main()
{
	DoSomething DS(2, 9);

	DS.doSomething(3, 7);

	DoSomething::v1v2_s args = {100, 200.0};

	pthread_t t;
	pthread_create(&t, NULL, DS.DS_helper, &args);
	pthread_join(t, (void**)&args);
	float res = args.retval;
	return 0;
}

Open in new window


If you could correct the existing code w/o trying to revamp the whole approach, I would appreciate that. (After this is done, then, sure, revamp the whole approach.)
Thanks in advance.
0
Hi!!!
I was going to send a struct from a client to a server using boost::asio::async_write_some, in this case boost::serialization and boost::property_tree come to help,
//boost::serialization
struct blank
{
    int m_id;
    std::string m_message;

    template<typename archive>
    void serialize(archive& ar, const short version)
    {
        ar & m_id;
        ar & m_message;
    }
};

blank info;

info.m_id = 1;
info.m_name = "Rasul";

std::stringstream ss;
boost::archive::binary_oarchive out_archive(ss);

out_archive << info;

Open in new window


So, now how can I send/receive out_archive using boost::asio asynchronously .. or
//boost::property_tree
boost::property_tree::ptree root;
root.put("id", 2);
root.put("name", "Rasul");

Open in new window

How can I send/receive root using boost::asio asynchronously??? (If you have some other ideas please share them)
0
#include <iostream.h>
#include <bits/stdc++.h>

using namespace std;
      
	  
	   struct Node
	   {
	       int data;
		   struct Node* next;
		   };
		   
		   
		   int small(struct Node* head)
		   {
		   
		   int min = INT_MAX;
		   
		   
		   while (head != NULL)
		   {
		   
		      if ( min > head->data)
			       min = head->data;
				   
				   head = head->next;
				   }
				   return min;
				   }
				   
				   
				   
				   void push (struct Node ** head ,int data)
				   {
				   	struct Node * newNode ;
					
					newNode->data=data;
					
					newNode->next = (*head);
					(*head) = newNode;
					}
					
				   
				   void display(struct Node* head)
				   {
				    while ( head != NULL ) 
					{
					   printf("%d -> ", head->data);
                          head = head->next;
					
					}
					cout << "NULL" << endl;
					}
				   
			int main()
			{
			   int x;
			  struct Node* head = NULL;
			  
			  
			   push(&head,5);
			   push(&head,10);
			   push(&head,19);
			   
			   cout << "Linked list is:"<<endl;
			   
			   display(head);
			   cout <<"The minimum element in linked list :"<<endl;
			   cout << small(head) <<endl;
			   
			   
			   return 0;
			   }

Open in new window

0
This isn't really a question; rather, it is a puzzle!!!

Please note, this is NOT an assignment of any kind (check my profile if you are unsure as to my tenure on the site). The idea is to spark some activity in the C/C++ topic areas and to have a little fun. Points will be awarded to the expert(s) who provide the most interesting solution. The idea is to have a little fun, promote discussion and have something interesting to think/talk about.

If this goes well, I plan on doing one of these types of puzzle questions on a regular(ish) basis. I would like to see expert colaboration, rather than experts just going gun-ho to get points. I will consider colaboration between experts when I finally award points. I will close this question once I believe it has reached a natural conclusion (ie. no futher productive activity).

So, let's start with the first puzzle. It's one that has been set many times before and I'd be interested in seeing different approaches to solving it. Please don't just search Google and copy/paste. I promise I will check and any plaigirised answers will be ignored (and probably deleted).

Let's go...

Your job is to write a program that, when run, outputs it's own source code (including comments) such that if the output was fed back into a compiler, built and run it would do exactly the same thing as the original program. The output must be word for word identical to the original source code, such that performing a diff between the original source …
1
I had this question after viewing Overlay a dialog box from a dll.
0
Will C++ and VB6 continue to work in newest versions of Windows?
We have some old program written in  C++ and VB6 and want to prioritise upgrading them to .NET.
If a new version of Windows will make them obsolete overnight then upgrading them is a high priority.  Otherwise not.
A similar question arises if processors move from 64 bit to 128 bit.
0
I have a program created using C++ that runs fine on all Windows 7 computers. But the application crashes on Windows 10 computers unless they select "Run as Administrator". This is a serious issue when distributing my software. Is there any way programmatically to allow the program to run in this hostile environment?
0
I will be given a set of X/Y points and their corresponding Z values. Z = f(X, Y), but I do not know the function f. The points will be clustered together and I don't expect pathological conditions. The local maximums and minimums will have extra sample points to help make the interpolation better. The goal is to come up with a smooth surface that represents the function f as close as possible.

The analyst providing me with the set of points of known XYZ points will also give me an XY rectangular grid; and at all the intersection points of horizontal and vertical lines, I need to provide a z-value.

One thought I had was to consider a point and look at 4 quadrants, and take the closest point in each quadrant, and using those 4 points or more to try to interpolate. Prefer to be able to use a curved surface to get the results rather than linear planes. One rule is that the final results will match the given XYZ points . The given points are known as anchor points or knots.

I am just looking for something functional. I am not interested in speed.

 I am not allowed to use binaries, so I will have to build from source code in Linux or Windows.

Thanks in advance.
Paul
0
I first started out trying to learn C# but found out that in order to code the trading strategies and functions that we want, we would have to use this package called Sierra Charts

The developer I am working with is very familiar with SC and pointed me to this C++ Tutorial https://www.sierrachart.com/index.php?page=doc/AdvancedCustomStudyInterfaceAndLanguage.php#CPlusPlusReferences

This software looks rather dated in comparison to something like MultiCharts https://www.multicharts.com/net/ which uses .NET.

I might consider switching at some point to another platform like MC .net version, but in all my research, I see that C++ is the most prevalent among traders.  It is fast, which is the main consideration, and lots of pre-written functions already exist for it.

So I have switched my focus, since I am developing in C++ currently with SC, to learning the basics of C++ over C#.

I have been through the tutorial above and think I have absorbed just enough of it to barely understand what it is, but I am determined and now want to find a better tutorial that won't take me too far off base from what I am trying to do which is to code trading strategies.

I'd still like to learn the basics of C++ a little bit better before really getting my feet wet with Sierra Charts as I am currently letting my developer work on developing the function, which he is much better off doing, without my interference.

I'd like a tutorial for C++ that is much more interactive, lets me …
0
i want to create one dialog control with three buttons dynamically and  same dialog to created dynamically again 12 dialog s with the same content and size  but 12 dialogs control  should appear tile in format.
0
Due to security concerns related to updates not being applied to third-party software libraries, we are trying to replace as many of these as possible with functionality provided by the operating systems and are looking into options with compression. Are there any common compression formats that both Linux and Windows understand and provide C or C++-callable functions to programs to compress to and decompress from using only the APIs provided by the operating systems as installed? Thanks for any information!
0
Background: i work in a red hat and Windows 10 environment. We have models written in Matlab and Simulink that the developers will convert to C++ in order to get higher speed simulations. We do not like the C++ code that can be generated from these two products. We have a simulation proprietary framework which provides us with many math APIs for C++.

We currently use C++03 with Visual Studio 2010 and g++. Lead developer has no experience with C++11 but he would like to convince a large community of divisions to upgrade to C++11 . I asked him what skill levels of developers would he be bringing in . He said his group cannot afford the best, and he believes that C++ 11 is more complicated than C++ 03. Recently I've been doing this survey of multithreading capabilities in C++11, boost, Pthreads, WIN APIs , and while I can see that C++11 features are rich , they are also complicated to use correctly . For example if you want to squeeze performance out of a program that uses many cores , then you have to learn about the C++11 memory model, and be aware of all the tricky race conditions that can occur when the high-level code is done out of order as result of compiler optimization .

 Could someone give me a list of C++11 features that an average C++ developer could use and explain how it is beneficial with a strong argument that we convince a large community of divisions to agree to upgrade to C++11 .

 Two items that come to mind are multithreading and dimensional …
0
Below is a snippet from a REST server application that I have written in Embarcadero C++ builder XE10.1 Berlin

void TWebModule1::Action1Get(TWebRequest *Request,TWebResponse *Response)
{
  Code here generates some JSON response based on the Request.....

// send the response
Response->ContentType 	= u"application/json";
Response->Content       = ... some JSON text

}

Open in new window


I wish to modify the REST server so as to return some html text in another Action handler but I need to know the value to assign to the Response->ContentType instead of "application/json"
Also what other values are valid Response->ContentTypes ?
0
how to create a user interface thread in mfc and UI thread will display  the  four times the dialog box should open.
0
Bloom Filter
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data definitely won't be found. Read on to find out more...
6
Hello!

I am a new member and I saw that you already have some old posts regarding dxf libraries.
I found the topics very useful for my search but they are a bit old.
For this reason, I am creating a new post for new suggestions and ideas!

I am searching for C++ (or C) libraries which can read dxf files, preferably all versions.
I have an issue with the license type as I want to use it for a commercial software.
So, I need a library with license MIT, 3-clause BSD or commercial.

I would be grateful if you have any ideas!
Thank you very much for reading this post.
0
I have a desktop App written in MS VC++.  I'd like to add some video capability: show various formats, grab still frame, maybe very simple editing.  What kind of SDKs are available and good?  Is there a need for me to go to C# to get the latest/best, or can I stick with my familiar C++ world?
0
I had this question after viewing Obtaining help with programming tasks.

The parts of the C++ program according to the graphic below include:

Comments - ok

#include statement <iostream> preprocessor directive - ok
Example from our SierraCharts strategy:  #include "sierrachart.h"

using namespace std; - ok, ours might be a shared dll library reference instead?
Example from our SierraCharts strategy:
SCDLLName("TPStrat1 DLL")

int main () - ok, no idea here?
Example from our SierraCharts strategy:
bool IsNewBar(SCStudyInterfaceRef sc, int& PreviousIndex)
statements - ok, ours might be if (if else) statements only?


Before the first IF statement
Before_the_first_if_statement_2017-1.png


C++ in general
parts-of-a-C---program.jpg
0
I am not a programmer and would like some help with programming tasks as they relate to trading.

Specifically, my current developer is using C++ with SierraCharts to code a trading strategy, that looks for signals in a real-time stock chart, and then does a lookup to find specifically which underlying derivative call option to buy based on the signal obtained from the stock chart.

It turns out that not all trading platforms will support this kind of complexity.
SierraCharts allows a trader to use the raw code in a real programming language which is also part of the reason for the choice of platform.

It also turns out that in order to use the strategy, with SierraCharts, a would-be customer wouldn't have to pay as many platform costs to use it.

This is so complex that it has been difficult to connect with developers that can do this kind of work.

I need to better understand the structure of the code perhaps, in order to know where to go seek help because I am thinking that "anyone" with C++ knowledge might be capable of helping.

Is my current understanding of the below items correct?

Namespace - contains keywords specific to C++, and hold various libraries that contain functions
Library - there are proprietary and non-proprietary libraries ?
Functions - related to particular fields such as stock trading
Keywords - specific to C++ in general
0
I have a code snippet shown below which does not compile. I was of the understanding that Embarcadero C++ Builder XE10.1 Berlin supported the C++ 11 standard ? The initialisation of a vector gives a compile error:

[bcc32 Error] Unit1.cpp(22): E2131 Objects of type 'vector<int,allocator<int> >' cannot be initialized with { }
  Full parser context
    Unit1.cpp(20): parsing:  _fastcall TForm1::TForm1(TComponent *)

Code snippet:
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
using namespace std;

#include <algorithm>
#include <list>
#include <vector>

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
	std::vector<int> mem = {1,2,3};
}
//---------------------------------------------------------------------------

Open in new window

0
I am installing my software and would like to pin a shortcut to the taskbar. I have created the shortcut into:

C:\Users\Ironduke\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar

but it does not show up on the taskbar. How can I instruct Windows to do with (without having the software user do it manually)?

Any help would be appreciated.
0

C++

57K

Solutions

24K

Contributors

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.