Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE
LVL 4
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

class Operator
{
public:
      // Perform the operation on the two inputs
      virtual double operate(double input1, double input2 = 0) = 0;
};

class Operand
{
public:
      virtual double getValue() = 0;
};

class CalculatorFactory
{
public:
      //Input: character of an operator (e.g. '+' for plus)
      //Output: an object of the correct Operator sub-class
      static Operator * createOperator(char symbol);
      //Input: string of sub-expression
      //Output: object of correct Operand sub-class (i.e. number vs expression)
      static Operand * createOperand(string input);
      //Input: String of expression
      //Output: Calculated value
      static double calculate(string input);
};

I am supposed to create an order of operation calculator using polymorphism, dynamic memory, and operator overloading. The prototypes for the classes cannot be modified but you can add additional functions.
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
Write a program that assists a cashier at a paint store. The program should ask the cashier for the number of
gallons (could be fractions) of paint a customer is purchasing, save the value the cashier entered, compute the total
cost of paint by multiplying the value the cashier entered by a $5/gallon, add a 6.25% sales tax and finally inform
the cashier of the total amount the customer owes.
You should use the C++ input and output objects (i.e. cin and cout) and not the C standard I/O library.
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 would like help on drawing a grid within  rectangle when the checkbox "show grid" is true.
Can anyone help me on that?
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
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
Free Tool: ZipGrep
LVL 10
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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
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 ,


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

Thank you
0
Hello ,

We are building an IDS/IPS/Waf system that reads the packets from PF_Ring and apply rules to IPTables / Netfilter / Ntuple .
That software needs to access to userspace for iptables and kernelspace for netfilter. So we already pipe the both side.
But our main concern is about the performace issue. Time is our biggest enemy and need to solve the problem in mikro / mili seconds.
So where is the best place working area for our  main core of software for performance ? kernel area or user area ? and why .

Thanks for information
0
Hello ,

I want to know if there is a possible way to apply BPF filter to drop packets on netfilter  


Thank you



#define __KERNEL__
#define MODULE
#include <linux/ip.h>             
#include <linux/kernel.h> 
#include <linux/module.h> 
#include <linux/netdevice.h>      
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h> 
#include <linux/skbuff.h>         
#include <linux/udp.h>      

#include <linux/ip.h>


              
static struct nf_hook_ops netfilter_ops;                        
static unsigned char *ip_address = "\x5D\xBB\xCD\x73"; 
static char *interface = "p1p2";                          
unsigned char *port = "\x00\x17";                       
struct sk_buff *sock_buff;                              
struct udphdr *udp_header;                              
unsigned int main_hook(unsigned int hooknum,
                  struct sk_buff **skb,
                  const struct net_device *in,
                  const struct net_device *out,
                  int (*okfn)(struct sk_buff*))
{
  if(strcmp(in->name,interface) == 0){ return NF_DROP; }  
  struct iphdr* iph = ip_hdr(skb);
  if(iph->saddr == *(unsigned int*)ip_address){ return NF_DROP; }   
        
        
        
	/**sock_buff = *skb;
	if(!sock_buff){ return NF_ACCEPT; }                   
	if(!(iph)){ return NF_ACCEPT; }              
	if(iph->protocol != 17){ return NF_ACCEPT; }                 
	udp_header = (struct udphdr *)(sock_buff->data + (iph->ihl *4)); 
	

Open in new window

0
Hello

Is there any body knows ready to use sub routine when we send an array it will draw sth. like that :

value |-------------------------------------------------- count
    0 |                                                     32167
    1 |                                                      9999
    2 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  1723569
    4 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@                        973472
    8 |@@@                                                 111055
   16 |                                                     14777
   32 |                                                       376
   64 |                                                       585
  128 |                                                        19
  256 |                                                         0
  512 |                                                         0

Open in new window

0
Hello Experts,

I have a C++ program which allocates named shared memory of a structure. I need to be able to read that same structure from a c# program. Here is my c# code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        [StructLayout(LayoutKind.Sequential, Size = 218)]
        public struct TEST_STRUCT
        {
            public long tnum;                     //size = 8
            public long pass_count;               //size = 8
            public long fail_count;               //size = 8
            public long try_count;                //size = 8
            public double sum_result;               //size = 8
            public double sumsq_result;             //size = 8
            public double min;                      //size = 8
            public double max;                      //size = 8
            public long histogram;                //size = 8*40
            public bool tested;                   //size = 4
            public bool passed;                   //size = 4 
            public double last_result;              //size = 8
        };
        

Open in new window

0
Enroll in September's Course of the Month
LVL 10
Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

I am trying to set permission on an application as read/execute only, I can achieve this by using c++ windows SetSecurityDescriptorDacl() function.

But after that admin can change it by right clicking on a file

    properties->security->advanced->Change Permission

But somehow antivirus prevents these charges on their application ..
0
//************************** tracks indexs*******************
/*
each track saved in sd card has index , so to play track number we will using it's index 
for example to play track number 1 we will using "00003"  index which will send to play track function 
all the same for the rest of all tracks 
*/ 
char buffer15[6]={"00001"};  // track 15 index 
char buffer16[6]={"00002"};  // track 16 index
char buffer1[6]={"00003"};   // track 1 index
char buffer2[6]={"00004"};   // track 2 index
char buffer3[6]={"00005"};   // track 3 index
char buffer4[6]={"00006"};   // track 4 index
char buffer5[6]={"00007"};   // track 5 index
char buffer6[6]={"00008"};   // track 6 index
char buffer7[6]={"00009"};   // track 7 index
char buffer8[6]={"00010"};   // track 8 index
char buffer9[6]={"00011"};   // track 9 index
char buffer10[6]={"00012"};  // track 10 index
char buffer14[6]={"00013"};  // track 14 index

//*************************

Open in new window


How can I access these mp3files via filename not index
0
Hello everyone.

I've seen that what I'm trying to do which is monitoring the file IO require the use of Window File System Filter driver and I've also looked into it but was a bit hard to understands especially as I'm not a C++ developer. What I want to achieve is to be able to trap file copy, creation, as well as file sources and destinations, lets say I'm copying a file within my computer I want to get the source path of the file as well as destination path of the file and also the file name as well and if possible with the application that is sending the file.

I saw that this can also inform you if there is file access(opening of file, reading of file) this is very much important to me to also get it if possible while the request of file open is created. I wan to trap this and if the file is one of my file then I want to first work on the requested file first (decrypt).

Thank you.
0
Hi Experts,

         I have a alpha numeric text of length (4096 to 8192)Bytes. I need a compression algorithm to compress and decompress text length upto (128 to 256)Bytes.

I have already tried some compression methods but not able to compress text upto (128 to 256)Bytes .
(eg: Zip.)

To perform this job we need only compression method not hash value.

Thanks In advance
0
language : c++
(tools : visual studio , acrobat reader)
thanks a lot
0
I had this question after viewing C++ COM Method with Optional Arguments.

I am trying to produce a COM object in Visual C++, where one of the methods accepts optional arguments. Below are the interface declaration, the class implementing the interface, and the implementation of the method taking an optional argument. As it stands, it compiles. But when I try to call the function from an ASP page using VBS with the supposedly optional parameter missing, I get the following error


Microsoft VBScript runtime error '800a01c2'
Wrong number of arguments or invalid property assignment: comObject.ShowFinalSql

Following code in IDL
interface IWPharma : IDispatch{
   [id(2), helpstring("method ShowFinalSql")] HRESULT ShowFinalSql([in] BSTR query, [in] BSTR cleanup);

in C++:
    STDMETHOD(ShowFinalSql)(BSTR query, BSTR cleanup) override

in VB with error:
SET comObject = CreateObject("WPharma.Main")

REM Тест #1
comObject.ShowFinalSql "CHECK_SIGNATURES 01/01/2017", ""
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.