Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x

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

Starting with small C++ console program with one function call is there any examples of how to convert that to an equivalent VB.NET program. I don't want to use the VISUALBASIC namespace.

Thanks
0
I try to compile a code that was successfully compile on Linux system.  This code hast the usage of std::unique_ptr but Visual Studio nags arround the common C++ usage. The code looks like

    std::unique_ptr<bxf2::bxf> document = nullptr;
    ofstream cerr("output.txt");
    
    try
    {
        xml_schema::properties props;
        document = move(bxf2::bxf_(bxf_file, 0, props));  (Line 29)
    }

Open in new window


THe error message is:

1>XSDValidator.cxx(29): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::auto_ptr<_Ty>' (or there is no acceptable conversion)
1>          with
1>          [
1>              _Ty=bxf2::bxf
1>          ]
1>          C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\memory(2420): could be 'std::unique_ptr<_Ty> &std::unique_ptr<_Ty>::operator =(std::unique_ptr<_Ty> &&)'
1>          with
1>          [
1>              _Ty=bxf2::bxf []
1>          ]
1>          C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\memory(2449): or       'std::unique_ptr<_Ty> &std::unique_ptr<_Ty>::operator =(std::nullptr_t)'
1>          with
1>          [
1>              _Ty=bxf2::bxf []
1>          ]
1>          C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\memory(2520): or       'std::unique_ptr<_Ty> &std::unique_ptr<_Ty>::operator =(const std::unique_ptr<_Ty> &)'
1>          with
1>          [
1>              _Ty=bxf2::bxf []
1>          ]
1>          while trying to match the argument list '(std::unique_ptr<_Ty>, std::auto_ptr<_Ty>)'
1>          with
1>          [
1>              _Ty=bxf2::bxf []
1>          ]
1>          and
1>          [
1>              _Ty=bxf2::bxf
1>          ]

Open in new window


What I have done wrong in Visual Studio? IS Visual Studio the wrong version to use?
0
I have a short meta-programming approach for POD type safety from a previous question:
https://www.experts-exchange.com/questions/29056989/C-03-Templatize-Type-Safety-Enforcement-Part-2.html

I see the benefits of meta-programming as simplifying the development process for units - I believe that all new developers would have to do is to include a units header file, and follow a simple recipe for defining new data types.

I wrote in that question:
Other dimensional analysis areas that I am leaning towards:
 1. Make the class name part of the template
 2. Make the set of enumeration values part of the template so that they are not universally available
 3. Be able to operate on two different families of units. One obvious example would be:
        "distance (meters) = rate (meters/sec) * time (sec)".
     But we will have many other cross-unit operations as well.

I thought that I may as well see if I can get some tips on these ideas. If these 3 goals are realistic, but too much for one question, I am happy to work on what is reasonable for one question.

At the moment, I have to transcribe the previous question to my workstation, and then sell the ideas here and from the previous question to my lead software developer. The PM and Systems Engineer definitely like the idea of POD type safety. I just hope the lead likes the template approach.
0
How to insert image or picture in turbo c
Plz me
0
I have a short program shown below that is also located in:
https://www.experts-exchange.com/questions/29056211/C-03-Type-Conversion-Errors-for-primitive-types-Part-1.html#a42295035

I would like to templatize it to reduce the amount of tedium in handling multiple type conversions. I only show three types here (Hz, KHz, MHz), but I will be adding GHz as well. To make the classes easier to create, I got this good tip on the beginnings of templatizing the type enforcement/conversion classes:

What I would like to do is be able to handle the below program which has a bunch of friends and multiple implicit conversions for each type.

If I can get some meta-programming technique (or just plain templatizing) to generate lots of this type of code, I would greatly appreciate seeing how to do this. I'll be having to deal with many other families of types, such as distance: (feet, inches, millimeters, meters); time(seconds, hours - yes, I know about chrono); speed, etc.
#include <iostream>

class Hz
{
	friend class KHz;
	friend class MHz;
public:
	explicit Hz(double val) : val_(val) {}
	Hz(const KHz & khz);
	Hz(const MHz & mhz);
	double operator()() { return val_; }

private:
	double val_;
};

class KHz
{
	friend class Hz;
	friend class MHz;
public:
	explicit KHz(double val) : val_(val) {}
	KHz(const Hz & hz) : val_(hz.val_ / 1000.) {}
	KHz(const MHz & mhz);
	double operator()() { return val_; }

	KHz operator*(double mult)
	{
		return KHz(val_ * mult);
	}

private:
	

Open in new window

0
Can someone help me write this program in c++?

 Suppose a teacher weights the four exams he gives 10%, 25%, 30%, and 35%.
Write a program that reads ten sets of four grades, prints the weighted average of each set, and prints the unweighted average of each test. The number of students should be in a global constant.

I know I need to use a for loop, but I'm not sure how to write it. Can someone show me how to code this along with guiding me through the code?
0
NestingLayout.png
Here is my layout i need this in visual studio c# or c++ please help me to soft this problem. here i requested to give me idea to process layout like this,

thanks in advance
0
I am working on a project where I need to convert between units.
To avoid the Mars Landing mishap, I hoping to enforce enhanced typing of primitive types.
http://articles.latimes.com/1999/oct/01/news/mn-17288

For example, not all doubles representing length are meters; some are feet, or miles.
I don't want a function expecting meters to compile if it is given a double which is in feet.

The below program compiled in VS-2010 (C++03 required), but not in ideone.com
https://www.ideone.com/YGzOCy
(There is a chance that when I copied it incorrectly from VS 2010 to ideone.com.)
In the code below I have 3 comments indicating the problem areas I have.
Could you help me fix this program to address these 3 comments?
class Hz;
class KHz;


class KHz
{
public: KHz(double val) {val_ = val;}
	operator double() const {return val_;}
	KHz operator*(double mult) {return val_ * mult;}
	
private:
	double val_;
};


class Hz
{
public:
	Hz(double val) {val_ = val;}
	
private:
	double val_;
};


// 1. Would like to avoid this explicit conversion function:
Hz cnvKHzToHz(KHz khz) {return khz * 1000.0;}


void doSomething(KHz khz) {;}


int main()
{
	Hz ret = 0;
	KHz valkhz = 4.0;
	ret = cnvKHzToHz(3.0); // 2. Would like to have a compiler ERROR to prevent argument of double
	ret = cnvKHzToHz(valkhz);
	
	// doSomething(ret); // 3. ERROR: "Cannot convert parameter 1 from 'Hz" to 'KHz'
}

Open in new window

Thanks in advance.
Paul

p.s. - For more information on this topic, see:
https://www.experts-exchange.com/questions/29056989/C-03-Templatize-Type-Safety-Enforcement-Part-2.html
0
Platform: Windows 7 Professional SP1 64-bit
Currently have 64-bit version of "Microsoft Visual Studio 2010 Tools for Office Runtime" installed, have a new application that is failing to install. MSI log indicates it is missing the 32-bit version of the 2010 tools. So I downloaded the tools from Microsoft at: https://www.microsoft.com/en-us/download/details.aspx?id=54251

It downloads file "vstor_redist.exe", and when I install it it's log states "Visual C++ 2010" (see below). Ok, I kind of understand how they may be the same thing, however it never shows in the registry or add/remove programs as "Visual Studio 2010 Tools", and my 3rd-party application is still failing with the same error. So my question is, why does the vstor install show up as C++? And how can I go about finding a 32-bit installer that populates
the registry with the actual name "Microsoft Visual Studio 2010 Tools for Office Runtime (x86)"?


Error in MSI log for 3rd-party application:
 -- This application requires Microsoft Visual Studio 2010 Tools for Office Runtime. Please launch the install using setup.exe to install this requirement.
Note: I was never given an exe, only the MSI (that's prefered anyway since I am distributing via SCCM and/or BigFix)



Excerpt from vstor_redist.exe installation:

Patch (c:\8feb62db887aa9967092084220c26d74\VC_Red_x86\msp_kb2565063.msp) Install succeeded on product (Microsoft Visual C++ 2010 x86 Redistributable - 10.0.40219). Msi Log:
[9/8/2017, …
0
I have a sample application written in C++ for a slap scanner. I am able to get the image scanned but do not know what to do with the data received. Can anybody guide me in the right direction?

I have attached the SaveImage Code from the sample app(Written in C++) and would like to know how convert it to vb.net. I am novice when it comes to C++.

I have tried to read the bytes from memory starting at the pointer returned to the tagImageData structure during the scanning process.

here is the structure that contains the image data:
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> Public Structure tagImageData
        Public Buffer As IntPtr '< Pointer to image buffer
        Public Width As UInteger       '< Image horizontal size
        Public Height As UInteger      '< Image vertical size
        Public ResolutionX As Double  '< Horizontal image resolution (in PPI)
        Public ResolutionY As Double  '< Vertical image resolution (in PPI)
        Public FrameTime As Double    '< Image acquisition time (in seconds)
        '< This value contains the time taken for acquisition
        '< from device (excluding processing time).
        Public Pitch As Integer       '< Image line pitch (in Bytes).
        '  Positive values indicate top down line order,
        '  Negative values mean bottom up line order
        Public BitsPerPixel As Byte   '< Number of Bits per pixel
        Public Format As Integer      '< Image color format
       …
0
Hi EE.

Does anyone know how can I make my app to self delete? In VB.NET I use this:
Process.Start("cmd.exe", "/C ping 1.1.1.1 -n 1 -w 3000 > Nul & Del " + 
          Application.ExecutablePath); 
Application.Exit();

Open in new window

How can I also archive that in C++, I'm using Visual C++ 2010 Windows forms.
0
What technologies are best suited for the highest performance web services to handle the heaviest loads? Thousands (even millions) of transactions per second?

I know that Node.js can handle thousand(s) sessions on a single thread. And I do not know of any other technology which handle more than one session per thread. Am I right about that? Are there others that can do this also?

What about real-time programming as it relates to web-services. Is there such a thing?

And how about a few general words about hardware deployment? Having a central API call which distributes calls to hundreds of more specialized web servers? What about Caching for successive related calls?

And what about Machine Learning? Can algorithms be optimized by existing Machine Learning algorithms that reduce the average response times of the most heavily load web service?

Thanks.
0
I have a dialog that is derived from our specific base class that is inturn derived from CDialog class
This dialog contains a combobox with combobox items in it (string)
There is a group box, labels, checkbox and a text box as well (I will call them grouped controls for this discussion)
If I select an item in index 0 from combo box, the Grouped controls are shown and if I select an item in index 1 from combo box, the group controls should be hidden
I have used the code to show or hide the controls as
void MyDerivedClass::HideMyControls(bool hide)
{
	int param = (false == hide)? SW_SHOW : SW_HIDE;
	
	CWnd* pCtrl = GetDlgItem(IDC_ENABLE_TP_DIRECTORY);	
	CRect myRect;
	pCtrl->GetClientRect(myRect);	

	GetDlgItem(IDC_STATIC_NOTE)->ShowWindow(param);//This is label control
	GetDlgItem(IDC_STATIC_DIR_NAME)->ShowWindow(param);//This is label control
	GetDlgItem(IDC_EDIT_TP_DIRECTORY)->ShowWindow(param);//This is text control
	GetDlgItem(IDC_STATIC_TP_GRPBOX)->ShowWindow(param);//This is label control
	InvalidateRect(myRect);	
	UpdateWindow();
}

Open in new window

The issue is the controls are still seen on the screen even after the above method is called with true parameter. If I move some other window on top of the (supposed to be) hidden controls, then it is actually disappears. So this seems to be a refresh issue. My assumption is that the InvalidateRect and UpdateWindow should have taken care of repainitng this. but is not happening.
Tried with InvalidateRect(NULL) to paint the whole screen, but still no use.

Could you please suggest how I can hide the controls? any clean way of doing this?

Note: when the controls are (supposed to be) hidden but are still seen on the screen, I will not be able to perform any action on those controls (like setting checkbox or typing in the text box).
So I believe that the controls are marked as hidden but not painted.
0
Is it true that XslCompiledTransform is the solution?  Any examples?  I tried to use XslCompiledTransform in my c++ code but compiling failed. I don't know how to enable CRL in my VS 2002.  Please help.
0
Hello  ,

I am trying to read an hex part as given below i am hitting firs 08 with if it is ok than getting the size with 0a -> 10 it is also ok but i couldnot get into a variable .


  08 0a 59 97 a9 ef 07 29 c3 28                    

Open in new window


                        if (kind == 8) {
					p++;
					uint8_t size = *p;
					p++;
					TS=(*(uint32_t *)p)
					//printk(KERN_ERR "4. TS %d ",(*(uint32_t *)p));
					p += (size-2);
				}

Open in new window

0
I build a simpel program ,

but the button input need to wait 1000ms , for the next reaction
any way to fix that problem.

int led1 = 13;
int led2 = 12;
int button = 7;
int buttonState;

void setup() {
  
  
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(button, INPUT);

}

void loop() {

  buttonState = digitalRead(button);

  
if (buttonState == HIGH) 
{
digitalWrite(led2 , LOW);


} 
else
{

digitalWrite(led2,HIGH); 
  
}
  digitalWrite(led1, HIGH);  
  delay(1000);                      
  digitalWrite(led1, LOW);    
  delay(1000);                      
}

Open in new window

0
I would like to use Png images while working in C++ Builder RAD Studio XE6. I am using graphics32 lib and I managed to install runtime and designtime packages. I can put the TImage32 component on my form, then I load the png image in TImage32, but instead of transparency, I get white color on the background. I just cant see what do I have to do, to get transparent png image on my form.

I would be very thankful for your help.
0
Hello ,

Is there any library to trace / ping an ip or a better / faster way to get the ttl of an ip address ?
0
Hi guys.

I'm using this code to read a text file locally and do the word search as needed but the problem is that the file which this app will be reading will be online on a web server and the problem is that the code I have now to read this text online I don't seem to figure out how I can split data so that I can still do word search just like how I do to a local file. Here is the code I use to read local file:

while(!in.eof() && getline(in, line, ','))
							 {
								if((offset = line.find(ID, 0)) == string::npos)
								{
									id = atoi(line.c_str());
									in >> dat;
									getline(in, NUMBER, ',');
									getline(in, line, '\n');
									
									KEY = (int)atof(line.c_str());
									
									if(ID ==id)
									{
										ID = id;
										//dst = dvs;
										va = KEY;
										
									}

Open in new window


Now this code part is the essential part of code as its what I want to be able to do in the following code which is the code that reads a file from the web.

    #include "stdafx.h"
    using namespace System;
    using namespace System::IO;
    using namespace System::Net;
    using namespace System::Text::RegularExpressions;
    int main(void)
    {
        Regex^ rxSubTitles = gcnew Regex("\\d.*>(?<subtitle>.*)<");
        String^ strFileIn = L"http://textfiles.com/adventure/221baker.txt";
        WebClient^ wc = gcnew WebClient();
        StreamReader^ fileWebIn = gcnew StreamReader(wc->OpenRead(strFileIn));
        String^ strData = "";
        while(!fileWebIn->EndOfStream)
        {
            strData = fileWebIn->ReadLine();
            if(rxSubTitles->IsMatch(strData))
            {
                // take ONLY the subtitle without additional decoration
                Console::WriteLine(rxSubTitles->Match(strData)->Groups["subtitle"]->Value->ToString());
            }
        }
        fileWebIn->Close();
        return 0;
    }

Open in new window

This code simply gets all the Titles.

Here is my text file structure:

111,7643876,2
324,254935,
730,021738248,1

Open in new window


As you can see each line has 3 data fields and
,

Open in new window

is the data separator and as you can also see that the 3rd field can sometimes be empty. I think if you can look at the structure and also look at my first code even though I didn't post the complete code on the first code but I think that s the main part which you may need as its also the main part I'm having problem with when trying to apply it to the second code.
0
Hello ,

I want to use given struct in a map as this : std::map<Web_Dumper, int> http_dumper;


but i am getting errors, where should i do mistake ?

struct Web_Dumper
{
    IP4 ip;
    const std::string Agent;
    const std::string Version;
    const std::string Host;
    const std::string Path;
    const std::string Ulke;
    long int Tarih;
    Web_Dumper(IP4  szip,const std::string sAgent,const std::string sVersion,const std::string sHost,const std::string sPath,const std::string sUlke,long int sTarih) : 
    ip(szip), Agent(sAgent) , Version(sVersion), Host(sHost), Path(sPath),Ulke(sUlke), Tarih(sTarih){}
    friend bool operator<(const Web_Dumper & ipt1, const Web_Dumper & ipt2) { return std::make_pair(ipt1.ip,ipt1.Agent,ipt1.Version,ipt1.Host,ipt1.Path,ipt1.Ulke,ipt1.Tarih) <  std::make_pair(ipt2.ip,ipt2.Agent,ipt2.Version,ipt2.Host,ipt2.Path,ipt2.Ulke,ipt2.Tarih); }
};

Open in new window




AnomalyDetector.c: In function ‘bool operator<(const Web_Dumper&, const Web_Dumper&)’:
AnomalyDetector.c:1311:173: error: no matching function for call to ‘make_pair(const IP4&, const string&, const string&, const string&, const string&, const string&, const long int&)’
     friend bool operator<(const Web_Dumper & ipt1, const Web_Dumper & ipt2) { return std::make_pair(ipt1.ip,ipt1.Agent,ipt1.Version,ipt1.Host,ipt1.Path,ipt1.Ulke,ipt1.Tarih)
                                                                                                                                   

Open in new window

0
X = 1   2
       3   4

y = 3   1
       4   2
how can i convert x to y????
0
Hello ,

I want to appy a system command with arguments from variables but i could not find an example any body has experience about this ?


This is what i want to do
system("/bin/bash  /etc/a.sh   %d %d",val1,val2);
0
Hello ,


Any body knows a sample for re-calculate checksums and drop packets on netfilter module ?

Thank you
0
Hello ,

We want to create fork subroutines on runtime and let it die after 180 seconds. But ;
We do not want to let the mirror all global variables that should cause high memory usage on the system , we just want to pass the variables to the fork and it will do a few small jobs then will end it self after 180 seconds is it possible to isolate from the other app ?
As far as i know when a fork start it completely clone the existing maps / arrays etc. and work in another road.
0
Hello ,

For a project we are using ip.h library of the linux.
As far as i check the library , http://www.cse.scu.edu/~dclark/am_256_graph_theory/linux_2_6_stack/linux_2ip_8h-source.html  , i could not find a way to check Window size , is there any way to read complete packet hex with this library and get the window size of packet hex like given below :

			long dec_Window_size = std::stol (packet_hex.substr(96,4),nullptr,16);

Open in new window

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.