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

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
On Demand Webinar: Networking for the Cloud Era
LVL 9
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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
How should i solve this :)


	std::string RANGE ;
			std::stringstream RANGEstream;
			for (std::pair<long int, int> element : TTL) {
				RANGEstream <<  element.first;
				RANGE = RANGE + RANGEstream;
			}

Open in new window



dinleyici.c:352:19: error: no match for ‘operator+’ (operand types are ‘std::string {aka std::basic_string<char>}’ and ‘std::stringstream {aka std::basic_stringstream<char>}’)
     RANGE = RANGE + RANGEstream;
                   ^

Open in new window

0
Hello ,


Is there any body know a way to send live message to kernel module like the given below. I want to send a message to it and let it write to logs the message
My message will be sended from the user space and the kernel module is working on kernel space




#include <linux/module.h>	/* Needed by all modules */
#include <linux/kernel.h>	/* Needed for KERN_INFO */

int init_module(void)
{
	printk(KERN_INFO "Hello world 1.\n");
	return 0;
}

void cleanup_module(void)
{
	printk(KERN_INFO "Goodbye world 1.\n");
}

Open in new window

0
on the C++2011 compiler why that warnings happens for this code part and how should i do the legal app.
(*((unsigned int*)&ip4[0]))




dinleyici.c: In constructor ‘IP4::IP4(const char*)’:
dinleyici.c:36:28: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   *((unsigned int *)&ip4[0]) = 0;
                            ^
dinleyici.c: In function ‘bool operator<(const IP4&, const IP4&)’:
dinleyici.c:44:96: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  friend bool operator<(const IP4 & ip1, const IP4 & ip2) { return *((unsigned int *)&ip1.ip4[0]) < *((unsigned int *)&ip2.ip4[0]); }
                                                                                                ^
dinleyici.c:44:129: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  friend bool operator<(const IP4 & ip1, const IP4 & ip2) { return *((unsigned int *)&ip1.ip4[0]) < *((unsigned int *)&ip2.ip4[0]); }
                                                                                                                                 ^
dinleyici.c: In member function ‘IP4::operator unsigned int()’:
dinleyici.c:51:67: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         operator unsigned int() { return (*((unsigned int*)&ip4[0])); }  // cast the pointer to low byte to unsigned int  }
                    

Open in new window

0
The given code below returning the given fault. I think it is a memory issue because we are always dumping and cleaning the map. How can i over come this issue


std::map<int, int > Protocol;  //Global Structure

Protocol.clear(); // Before pushing items i am clearing old values
	
int dec_protocol = std::stol (hex.substr(46,2),nullptr,16);
Protocol[dec_protocol]++;

Open in new window




*** Error in `./dinleyici': double free or corruption (!prev): 0x0000000000d727f0 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x7c503)[0x7f60126a8503]
./dinleyici[0x407de7]
./dinleyici[0x407d97]
./dinleyici[0x407d97]
./dinleyici[0x407d97]
./dinleyici[0x4072ca]
./dinleyici[0x4079e5]
./dinleyici[0x408fc4]
./dinleyici[0x404953]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7f601264db35]
./dinleyici[0x404f74]
======= Memory map: ========
00400000-004a1000 r-xp 00000000 fd:02 67684348                           /home/c++/calismalar/Project_V1_09.08.2017/dinleyici
006a0000-006a2000 r--p 000a0000 fd:02 67684348                           /home/c++/calismalar/Project_V1_09.08.2017/dinleyici
006a2000-006a3000 rw-p 000a2000 fd:02 67684348                           /home/c++/calismalar/Project_V1_09.08.2017/dinleyici
006a3000-006a5000 rw-p 00000000 00:00 0 
00d52000-00d93000 rw-p 00000000 00:00 0                                  [heap]
7f600c000000-7f600c021000 rw-p 00000000 00:00 0 
7f600c021000-7f6010000000 ---p 00000000 00:00 0 
7f6011ca9000-7f601262c000 rw-s 00000000 00:09 584508            

Open in new window

0
Hello ,

Is there any possible way remove if the number of rows exceeds X the oldest (Total_Row - X ) count rows.
0
hello

static std::map<Log, int> Logmap_;
static std::map<Log, int> Logmap_new;


Is there any possible way to search in a hash table which has values like given below 16-24. char for 4F94CFAE  and put founded lines to Logmap_new from  Logmap_ with values



DC38E1AC9B89A0369F557CAA080045100104FC62400040069BD5257B628A4EAFCAF70016F273CA35B6FD50ED7F8D50180094CE830000BC2411DB2762C01F5AE797C64F94CFAE2833E406D8376DB4005717643E0DBA31A7D5BA073799AB93CEE4E22A357C
DC38E1AC9B89A0369F557CAA080045100338FC634000400699A0257B628A4EAFCAF70016F273CA35B7D950ED7F8D501800940CEE0000974CEDC48B7C50744D96523A13FBD77D4CCAE45BF24F9FB91E7B43600A7397E2DD9788F7E7837D69170BD5A94E83
A0369F557CAADC38E1AC9B8908004500004CCC3440003A06D2CB4EAFCAF7257B628AF273001650ED7F8DCA35B2B150182000D53900003068613A5E81D88EEB70EC9A0B45304A8266890A03CB36E112653052C767CCFEC9281625
DC38E1AC9B89A0369F557CAA08004510004CFC64400040069C8B257B628A4EAFCAF70016F273CA35BAE950ED7FB15018009413FA0000E1FC591EA86C2AEA5245848504E41776637B03D3261D943B020BA01464A715C32B4E4610
A0369F557CAADC38E1AC9B89080045000028014040003A069DE44EAFCAF7257B628AF273001650ED7FB1CA35B4CD50101FEFAC0D0000000000000000
A0369F557CAADC38E1AC9B89080045000028DDF640003A06C12D4EAFCAF7257B628AF273001650ED7FB1CA35B6FD50101FEEA9DE0000000000000000
A0369F557CAADC38E1AC9B8908004500002807BA40003A06976A4EAFCAF7257B628AF273001650ED7FB1CA35B7D950101FF9A8F70000000000000000

Open in new window

0
Hello ,

The given code below returns an answer as given at the bottom . I need to put each line into an array .  how should i do it ? I mean i need to build line in for i loop and then need to add to array.

Thank you


	for (int i = 0; i < (bpf_u_int32) pkthdr->caplen; i++) {
		printf("%02X%s", (uint8_t)packet[i], (i + 1)%2 ? "" : "");
	}
	printf("\n");

Open in new window



DC 38E1 AC9B 89A0 369F 557C AA08 0045 C002 40B1 6900 0040 01ED A925 7B62 8A3B C115 2403 0337 A600 0000 0045 0004 1846 F000 00FD 1199 FA3B C115 2425 7B62 8AC1 3B00 1704 0400 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 00
A0 369F 557C AADC 38E1 AC9B 8908 0045 0004 1846 E900 00FD 11B0 6759 7DE1 0125 7B62 8A7D 5900 1704 0400 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 00
A0 369F 557C AADC 38E1 AC9B 8908 0045 0004 1847 7600 00FD 1188 6C7E 94E3 5825 7B62 8A94 7E00 1704 0400 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 00
A0 369F 557C AADC 38E1 AC9B 8908 0045 0004 1847 9100 00FD 1168 74B4 AECD 1B25 7B62 8AAE B400 1704 0400 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 00
A0 369F 557C AADC 38E1 AC9B 8908 0045 0004 1847 8C00 00FD 1147 4C4D D055 2725 7B62 8AD0 4D00 1704 0400 

Open in new window

0
[Webinar] Lessons on Recovering from Petya
LVL 9
[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Hello ,

I got a code like the given below , there is no begin and end values but it enters the if statement different parts but i could not understand why or how , should somebody tell me how this values changes on incrementIp function

	
struct SharedData
{
	bool done;
	pthread_mutex_t mutex;
	unsigned int ip_ring[100];
	int begin;
	int end;
	void shared_data() { memset(this, 0, sizeof(SharedData));}
	void incrementIp(unsigned int ip4){
		
		pthread_mutex_lock(&mutex);
		if ((end+1)%100 == begin)
		{			
			pthread_mutex_unlock(&mutex);
			incrementIp(ip4);
		}
		else
		{
			ip_ring[end] = ip4;
			end = (++end)%100;	
		
		}
		pthread_mutex_unlock(&mutex);

	}
	void synchronizeIps(std::map<IP4, int> & ip4map)
	
	{  
		pthread_mutex_lock(&mutex);
		for (int n = begin; n != (end+1)%100; n = (n+1)%100)
		{
			int ipaddress_decimal;
			memcpy(&ipaddress_decimal, &ip_ring[n], sizeof(unsigned int));
			struct in_addr dst_addr;
			dst_addr.s_addr = __bswap_32(ipaddress_decimal);
			char *dot_dst_ip = inet_ntoa(dst_addr);
			ip4map[dot_dst_ip]++;
			begin = n;
		}
		pthread_mutex_unlock(&mutex);
	}
};

Open in new window

0
when i add an ip to my hashtable from main process before start fork or in the forked process child it count independantly num_entries then the normal process in the program.

How should i solve to not behave them independently ?

	void child(){
		int j = 0;
		for (; j < 5000; ++j)
		{
		    int num_entries = ip4map.size();
		    printf("%d   \n",num_entries);
			usleep(500000);
	            
		}
	}

Open in new window


	struct IP4
	{
	    unsigned char ip4[4];
	    IP4(const char * szip) 
	    {
	        const char * psz = &szip[0]; int n = 4;
	        *((unsigned int *)&ip4[0]) = 0;
	        do 
	        {
	            ip4[--n] = (unsigned char)atoi(psz);
	            psz = (const char*)strchr(psz, '.');
	        }
	        while (n > 0 && NULL != psz++);
	    }   
	    friend bool operator<(const IP4 & ip1, const IP4 & ip2) { return *((unsigned int *)&ip1.ip4[0]) < *((unsigned int *)&ip2.ip4[0]); }
	    operator std::string() 
	    { 
	        std::ostringstream oss; 
	        oss << (int)ip4[3] << '.' << (int)ip4[2] << '.' << (int)ip4[1] << '.' << (int)ip4[0]; 
	        return oss.str(); 
	    }
	};
	std::map<IP4, int> ip4map;

Open in new window

0
Hello

we normally develop softwares on perl , we need a code structure like that for C++

	    $udp_dst_ip{$dst_ip}{src}++;
	    $udp_src_ip{$dst_ip}{$src_ip }{src}++;
	    $udp_src_port{$dst_ip}{$src_port }{src}++;
	    $udp_dst_port{$dst_ip}{$dest_port }{src}++;
	    $udp_tos{$dst_ip}{ $tos }{src}++;
	    $udp_ttl{$dst_ip}{ ($ttl) }{src}++;
	    $udp_packet_length{$dst_ip}{ $packet_length}{src}++;
	    $udp_data{$dst_ip}{$full_data }{src}++;

Open in new window


udp_dst_ip is an hash table when ever i add sth in it , it add one to souce count
for ex.

udp_dst_ip : 185.9.159.2
udp_dst_ip : 185.9.159.3
udp_dst_ip : 185.9.159.4
udp_dst_ip : 185.9.159.2


that returns -> $udp_dst_ip{185.9.159.2}{src} -> 2

and this are double layered hash tables :   $udp_src_ip{$dst_ip}{$ttl }{src}++;  

for ex.

udp_dst_ip : 185.9.159.2  & ttl : 115
udp_dst_ip : 185.9.159.2  & ttl : 116
udp_dst_ip : 185.9.159.2  & ttl : 117
udp_dst_ip : 185.9.159.2  & ttl : 115
udp_dst_ip : 185.9.159.2  & ttl : 115

and this time  $udp_src_ip{185.9.159.2 }{115}{src} returns 3


is there any mechanism on C++ like that ?
0
Hello


printf("0x%02X%02X", (uint8_t)packet[56], (uint8_t)packet[57]);

Open in new window


That returns me the hex of 1460 decimal value.   (0x05B4)  how should i get the value as integer 1460 ?

Thank you
0
Are there any instructors like
simon allardice
from lynda.com, plursight.com
who explain computer science concepts without using a scripting language.

Just verbally.

Please add (or subtract) zones
0
I'm programming Infineon TC29x Aurix Tricore Microcontroller based embedded system in 'C' language.
 
Consider stack starting at address 0x5000 0000.  The stack size is 0x1000.  

If I add 0x1000 to current stack pointer(Register A10) and store result in A10, then I should get underflow error.

What might be the code in assembly to change stack pointer?  something like following:

stw a10, 0x1000(a10)   # I'm not sure if stw is correct opcode ?

what are other options to create stack undeflow exception?
0
I'm attempting to integrate some functionality into a C-Language DLL that I use with my PowerBuilder application in order to manipulate Active Directory users without having to buy an expensive package or do the work manually.  I basically copied the following code (found on more than one web site) and the results of the compile return errors that both the "CreateDSObject" and "Release" functions are not members of the "IDirectoryObject" or "IDispatch" structures.  Here's the code I'm using:

        HRESULT                  hr;
      IDirectoryObject              *pDirObject;
      ADSVALUE                  sAMValue;
      ADSVALUE                  uPNValue;
      ADSVALUE                  classValue;
      LPDISPATCH                  pDisp;
      REFIID                        IID_IDirectoryObject;
      
      ADS_ATTR_INFO  attrInfo[] =
      {  
            { L"objectClass",            ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, &classValue,      1 },
            { L"sAMAccountName",      ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, &sAMValue,            1 },
            { L"userPrincipalName", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, &uPNValue,            1 },
      };
      DWORD dwAttrs = sizeof(attrInfo)/sizeof(ADS_ATTR_INFO);
      
      classValue.dwType                        =      ADSTYPE_CASE_IGNORE_STRING;
      classValue.CaseIgnoreString            =      L"user";
      
      sAMValue.dwType                              =      ADSTYPE_CASE_IGNORE_STRING;
      sAMValue.CaseIgnoreString            =      L"browvick";
      
      uPNValue.dwType                              =      ADSTYPE_CASE_IGNORE_STRING;
      uPNValue.CaseIgnoreString            =      L"Vicky_Brown@gmail.com";
      
      hr = ADsGetObject(      L"LDAP://DC=domainname,DC=com",
                                    IID_IDirectoryObject,
                                    (void**) …
0
Hi, dear experts:

I have a stupid question here, I used MFC for a long time, I still don't know why should I can the base class handler even when I provide the function to handle the message, here is an example:

class CMyDialog : CDialog
{....
}

void CMyDialog:OnLButtonUp(UINT nFlags, CPoint point)
{
    MyHandler();
    CDialogBox::OnLButtonUp(nFlags, point);
}

In fact when Class Wizard generate the message handler, it added base function call CDialogBox::OnLButtonUp(nFlags, point);

Here now here is my question, why do we need to call this function? what if I do not call this function?

Thanks for your help.
0
Hello,
my code works just fine and I got no error message.
But how can I check the the delete was done? Like a if - else routine

//%%%%%%%%%%%%%%%%%%%%%%%%%% Löschung %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	//SQL Server
	m_strConnection = _T("Driver={SQL Server}; Server=DSERVER; Database=OMSDATEN;Uid=;Pwd;");
		
	 //-----------------------------------------------------------------------------------------------------------
	//Initialize the Recordset and binding pointers
	m_ptrRs = NULL;   
       m_piAdoRecordBinding = NULL;   

	//Initialize the COM environment
	::CoInitialize(NULL);
	try
	{
		//Create the recordset object
		m_ptrRs.CreateInstance(__uuidof(Recordset));  

     
//======================================= Delete ==============================================================
   sql.Format("DELETE LogBuch FROM LogBuch WHERE Zeitstempel>='%s' AND Zeitstempel<='%s'",str_loeschen_von,str_loeschen_bis);
//============================================================================================================
		 
      _bstr_t bstrQuery(sql);
  
		//Open the recordset object Tabelle 
 m_ptrRs->Open(_variant_t(bstrQuery),(LPCTSTR)m_strConnection, adOpenDynamic, adLockOptimistic, adCmdUnknown);

		//Get a pointer to the record-binding interface Coils
		if(FAILED(m_ptrRs->QueryInterface(__uuidof(IADORecordBinding),(LPVOID *)&m_piAdoRecordBinding)))     _com_issue_error(E_NOINTERFACE);
  
		//Bind the record class to the recordset
	//	

Open in new window

0
Free Tool: Path Explorer
LVL 9
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

We will install a visual studio version, probably 2015 or 2017 so that we can be ready for the present someday in the future. But for now we have to deliver our source code to the customer who only knows about Iso c++03.

This means that if a developer inserts some newer c++11/14 constructs into our code base, then I want the computer to issue fatal errors forcing the developer to have to conform to c++03.

I found this link that does not appear to go back far enough in time.
https://msdn.microsoft.com/en-us/library/mt490614.aspx

If you have an answer, please provide a relevant link that supports your response so that I can show my manager. Thanks.

Using Windows 10.
0
I use : to create  a new HWND

But requires the strike code for the window HWND chance his size

ex:  
bool HWND (chance size)
{
x = windowX
y= windowY

}


BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

Open in new window

0
i use,
hwndEdit = CreateWindowExW(WS_EX_CLIENTEDGE, TEXT("Edit"), NULL, WS_CHILD, 10, 10, 200, 150, hWnd, (HMENU) NULL,NULL,NULL );
ShowWindow(hwndEdit, SW_SHOW);

Open in new window


to add a text box of one line , now i want to add a multi line field.
2017-07-18--6-.png
0
Hello,

after solving some ugly other problems with make, I run now into the problem about the CXXFLAGS. It looks like make do not use this FLAGS.  My makefile looks like:

CXX = g++
CXXFLAGS = -g -std=c++11 -Wall -pedantic
LDFLAGS=-g

root := /usr/share/doc/xsd/examples

include $(root)/build/cxx/rules.make
include $(root)/build/xsd/tree-rules.make




$(CXX) $(CXXFLAGS) -c 05_bxf2.cxx

XSDValidator.o:
	$(CXX) $(CXXFLAGS) -c XSDValidator.cpp

XSDValidator:
	$(CXX) $(LDFLAGS) -o XSDValidator.o 05_bxf2.o

clean:
	rm -f *.o

Open in new window


The repsone I got in termional after calling make

g++ -W -Wall -O3 -c 05_bxf2.cxx

Open in new window


This is not what I added to the makefile. Any idea why make do not use the Flags?
0
Hallo,

When i, wane add a new EDIT child window which the user can type text from the keyboard.
a normal text box works, but when I challenge  CreateWindowExW( EDIT ..)

and  BUILD and run the program from my compute noting happens.

Do i miss the paint code or something.

//  Add a new TEXT imput box
//CreateWindow(TEXT("EDIT"),TEXT ("VALEU"), WS_VISIBLE | WS_CHILD | WS_BORDER ,10,10 ,200,25,hWnd, (HMENU) NULL,NULL,NULL );

// Add a new TEXT edit window

CreateWindowExW(WS_EX_CLIENTEDGE, TEXT("Edit"), NULL, WS_CHILD, 10, 10, 200, 25, hWnd, (HMENU) NULL,NULL,NULL );
			

Open in new window

Untitled.jpg
0
I have really problems to understand makefile and its rules.
I created a makefile that works perfect. Now I want to remove objects before compile but it do not work with rm -f *.o
I get always the message "Missing seperator. stop"

# Build
# /opt/rh/devtoolset-4/root/user/bin/
clean:
    rm -f *.o

root := /usr/share/doc/xsd/examples

include $(root)/build/cxx/rules.make
include $(root)/build/xsd/tree-rules.make

XSDValidator: XSDValidator.o 05_bxf2.o
05_bxf2.o: 05_bxf2.cxx 05_bxf2.hxx
XSDValidator.o: XSDValidator.cpp 05_bxf2.hxx

Open in new window


Any Idea what I do wrong? Without "clean: rm-f *.o" it works well. I also tried to use a tab before "rm"
But nothing helps. It looks like "rm" do not work in makefile?
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.