Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium







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

What is C++ without OOD ?
What is C++ with OOD?
I think maybe one of my .cpp files is not getting linked.  Makefiles are new to me but I think this one is correct.

#Use the g++ compiler
CC = g++

# Compiler flags:
#   -Wall (most warnings enabled)
#   -g (for debugging with gdb)
CFLAGS = -Wall

# Executable name:
TARGET = book_collection

all: main.o book_collection.o book_database

$(TARGET): main.o book_collection.o
	$(CC) $(CFLAGS) main.o book_collection.o -o $(TARGET)

main.o: main.cpp book_collection.h
	$(CC) $(CFLAGS) main.cpp -c

dvd_collection.o: book_collection.cpp book_collection.h
	$(CC)  $(CFLAGS) book_collection.cpp -c

	rm *.o *~ $(TARGET)

Open in new window

There is no .o file for the collection.cpp showing when I run an ls command. Here is the ls:

     book_collection.cpp  book.h    main.o    Makefile~
     book_collection.h    main.cpp  Makefile  user_collection.txt

Here is a small portion of the error messages I'm getting.  

g++    -c -o book_collection.o book_collection.cpp
book_collection.cpp: In member function ‘void book_collection::read_from_file(std::string)’:
book_collection.cpp:173:22: error: no matching function for call to ‘getline(std::ifstream&, int&)’
book_collection.cpp:173:22: note: candidates are:
In file included from /usr/include/c++/4.7/cstdio:44:0,
                 from /usr/include/c++/4.7/fstream:43,
                 from book_collection.cpp:11:
/usr/include/stdio.h:675:20: note: __ssize_t getline(char**, size_t*, FILE*)
/usr/include/stdio.h:675:20: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/4.7/string:54:0,
                 from /usr/include/c++/4.7/bits/locale_classes.h:42,
                 from /usr/include/c++/4.7/bits/ios_base.h:43,
                 from /usr/include/c++/4.7/ios:43,
                 from /usr/include/c++/4.7/ostream:40,
                 from /usr/include/c++/4.7/iostream:40,
                 from book_collection.cpp:8:
I read somewhere that use of RTOS helps code resue?   How ?
Hi Experts,

I have an issue where I have a simple application that exposes a web server for inter-process communication.  This application is meant for a single user to make requests to it.  It is not a windows service.

If someone logs out, no problem.  The application is shut down and so the web server goes away.  But if someone uses the user switching functionality - the application remains and will respond to requests that come in on that port from a separate user account.

How can I fix this?

Thanks for any ideas!
I have a C++ MFC app with multiple windows derived from CFormView. How can I send back and forth a structure between windows.
I cannot retrieve any string from a set container if the string has numbers in it. I am able to successfully retain any string that contain only characters, but if I add a string to the container that contains even one number I receive an error when trying to retrieve it using wprintf(). See my code below:

typedef basic_string<wchar_t> tstring_t;
typedef set<tstring_t> tset_t;
tset_t groupsFound;

wchar_t bufName[MAX_PATH]; (this is populated by another function)


_tprintf(_T("# of elements in groupsFound: %i\r\n"), groupsFound.size());

for (tset_t::iterator it=groupsFound.begin(); it!=groupsFound.end(); ++it)
	_tprintf(_T("%s\n"), *it);

Open in new window

I have an MFC SDI application with multiple CFormView pages and would like to build a left-side icon+text navigation panel, aiming for a modern look & feel. I'm looking for MFC C++ code examples.

Some of the methods that I have considered include:

CMFCPropertySheet: looks OK but I don't want the extra region at the bottom of the frame containing the OK & Cancel buttons. Even if we manually hide them, I think an empty region might still remain.
PropertySheet example
CMFCOutlookBar: looks nice but I'm only interested in creating the tab buttons (SetMode2003) without generating the extra tab pane contents above the buttons.
OutlookBar example
CMFCTabCtrl: doesn't appear to support a vertical style.

More specifically, what would be the most straightforward way to produce a navigation bar similar in concept to the following example (on the left side)?
GUI navigation example
Platform: Windows XP/Vista/7
IDE: VS C++ 2012 Pro
I have a small issue with COM. I wrote a console program with COM, which opens Internet Explorer hidden to the user and operates on a backoffice. Well, the problem is that when send a " click " on a link with " PostMessage ", a new tab opens and the browser becomes visible. ¿Why is this happening? ... ¿Can I prevent this behavior?.

Some code:

hr = CoInitialize(NULL);

if (FAILED(hr))
    cout << "Error ConInitialize\n";

IWebBrowser2 *pwb2;

hr = CoCreateInstance(CLSID_InternetExplorer,

if (FAILED(hr))
    cout << "Error CoCreateInstance\n";

hr = pwb2->put_Visible(VARIANT_FALSE);  // Turn on hidden, works fine.

if (FAILED(hr))
    cout << "Error blah blah\n";

Open in new window

After that I get the document and I send a click on a link with PostMessage and opens a new tab, but the browser becomes visible. ¿¿Why is that?? ¿¿How I can fix it??

Thanks any help. :)

I need help on using regular expressions with c++. I am willing to get digit/integer value after the character "Off". The input is like this:

Off 9

So, I need value 9.

Please guide me.

I am facing an issue with printing in Polish language.
This is not a character related issue but related to the Windows XP locale, Polish.

The printing is done from a system running on WES2009 to a network printer.
The print content is sent to this system by another system over the network.

When the language of the WES2009 system is English the contents are printed in Times-Roman.

But when the language is changed to Polish or Hungarian, the same content is printed in the ISO font.

I am not an expert in postscript commands, and also it has been difficult to browse thru all the legacy source code, one thing I could find out was, the font being sent is "Times-Roman-ISOLatin1".

I tried to debug the issue:

I commented the code which is concatenating the string "-ISOlatin1" to the font string "Times-Roman", now the print is in Times-Roman. Why is this affecting only when in Polish and not in English?

Another part of the code: modifies the font if locale is not Polish.
I removed the check (so it is not locale dependent), but with this change, I see the printer data LED blink twice but doesn't print anything.

My suspect is the first part of the code.

Could someone help me understand the link between the OS locale and ISOLatin1.
I can do some more debugging based on your suggestions.

I have attached prints in both the locales.

Note: I cannot post the exact code here, but I have ensured no miss in logic.

   /* Create the iso font name by 

Open in new window

My compile  is failing saying that "error C2039: 'bind2nd' : is not a member of 'std'"---yet this existed i\n vs2005 when I compiled it.

was it replaced with something else? Why did they remove it?

return typename
std::find_if(begin(),std::binder2nd(McuFileObjectFinder<FileObject, BaseObject>(), pObject));

In vs2005 this existed in C:\Program Files\Microsoft Visual Studio 8\VC\include\functional

template<class _Fn2,
      class _Ty> inline
      binder2nd<_Fn2> bind2nd(const _Fn2& _Func, const _Ty& _Right)
      {      // return a binder2nd functor adapter
      typename _Fn2::second_argument_type _Val(_Right);
      return (std::binder2nd<_Fn2>(_Func, _Val));
I am seeing the error message below when  compiling+linking my MFC C++ project which I am upgrading to vs 2013.

How do I change project settings to specify x86 machine type to eliminate the WARNING?

warning LNK4068: /MACHINE not specified; defaulting to X86

I am seeing the error below and my suspicion is that it is happening because there is no name space specified for my own IDocument' definition.

Any idea how to fix this? Is there a way to tell which namespace a particular line is actually in? There are so many levels of includes that the name space information is obscured.

 1>c:\companybuild\companyfilter\release\_intermediate\automation\ad20.tlh(124): error C2872: 'IDocument' : ambiguous symbol
                 could be 'c:\companybuild\companyfilter\release\_intermediate\automation\ad20.tlh(98) : IDocument'
                 or       'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\atlhandler.h(161) : ATL::IDocument'
I am seeing the error below trying to upgrade from vs2005 to vs2013. The original version of the code was created in VS 6.0.

I added the #pragma to disable the warning yet I am still seeing the warning:

#pragma warning( disable : 4996 )

C4996: 'MBCS_Support_Deprecated_In_MFC

 Build started: Project: ResizableLib, Configuration: Release Win32 ------
1>  StdAfx.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\afx.h(38): warning C4996: 'MBCS_Support_Deprecated_In_MFC': MBCS support in MFC is deprecated and may be removed in a future version of MFC.
1>          C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\afx.h(33) : see declaration of 'MBCS_Support_Deprecated_In_MFC'
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
virtual ParameterResult setValueRaw    (const char * val, unsigned short size, bool force = false) 
        if (size == LONG_SIZE)
           char *tv = new char[size];
           tv[0] = val[2];
           tv[1] = val[3];
           tv[2] = val[0];
           tv[3] = val[1];
           ParameterLong::setValue(tv, size, force);
           delete[] tv;
          return getResultId();                                                      

Open in new window

Above is how I did it.  Please share a better solution ?

We use Keil tools.  We write code for NXP LPC2468 ARM 7 Microcontroller.

Most Significant word is      00 01
Leastg Significant Word is   00 05

Example, val will be pointing to four bytes as follows:
01 00 05 00

After running the function:
05 00 01 00

I need help on how to read unknown file format. I can open that file format using Notepad and I can see the content. I tried to read file in way like we read text file but I cannot.

Please let me know how can I read unknown files which I can open with Notepad.


I need help to create multidimensional array in c++. I need to store unknown records with 3fields. I hope, my choice for multidimensional array is correct. I want to store fields like

SupplierID | Withdraw | Deposit
..               |        ..        |
..               |       ..         |
..               |        ..        |

Hi I try to write 8 bit bmp but found that there is some bytes that wasn't be in file.
After 2 bytes BM always appears 2 extra bytes (and they are not empty). I removed almost everything from code to find where is the problem.

 typedef struct  {
      char B;
      char M;
      int width ;//4 bytes
      int height; //4 bytes
       } BMPHEAD;

     BMPHEAD bh;

   bh.width =819;
    bh.height= 460;
  file.write ((char*)(&bh), sizeof(bh));

Open in new window

but when I open created file in Hex editor I see 12 bytes not 10 as expected. There is 2 extra bytes (byte 3 and 4).
Can any one tell me what's the problem with my code?
What are some ways to reduce power consumption in an embedded system through firmware?
I'm converting an old legacy program to a new OOP design, and I'd like to include Unit Testing, since I've read that's so wonderful.

I'm realizing my OOP design is a huge tree structure of classes.

At top I have a Machine class.

The Machine class has a Model class, a View class, and a Controller class. Each of those classes contains numerous other classes, and those classes in turn contain other classes, and on and on.

It appears Unit Testing has to be done from the bottom up. I can only easily create a leaf class—a class which has no subclasses.

I can't easily create a Machine class, for instance, because the entire tree of other classes that are needed haven't been written yet.

Are OOP programs grown from the bottom up? I write the leaf classes first, write Unit Tests for those, then the classes that use those leaf classes, and work my way up?

I'd like to test how the controller writes to the screen, to see if that actually works, but to do that I need to instantiate a Controller class, and a Screen class, and the Machine class is what hooks them together, but I can't create a Machine class because the entire tree of other classes involved haven't been written yet.

So it's sounding like I can't test the design to see if it's viable until all the code has been written. How does one get around this?

For example (see attached UML diagram), to test if MainMenuController can put text on the screen, I have to create classes
I need to create path to write binary file. I have path to MyDocuments folder and now I try to do some thing like that MyDocuments/bin.file
CHAR folder_path[MAX_PATH];
string path = folder_path.c_str() + "/myfile.bin";

Open in new window

this path I'll use in
ofstream outfile(path, std::ios_base::out | std::ios_base::app);

Open in new window

For some reason the way I create path wrong.
Dear Experts,

I am trying to bring up a vagrant windows machine. I have already created the base box and imported into vagrant with veewee. Now its the moment of truth - I need to edit the Vagrant file so that when I run Vagrant up command the VM can boot itself. Attached is my Vagrant file.

Runing VAGRANT UP with the current Vagrant file I receive the output of:

vagrant up
/Users/rtinoco/windows2008R2/Vagrantfile:65:in `block in <top (required)>': undefined local variable or method `vb' for main:Object (NameError)
	from /Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/config/v2/loader.rb:37:in `call'
	from /Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/config/v2/loader.rb:37:in `load'
	from /Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/config/loader.rb:104:in `block (2 levels) in load'
	from /Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/config/loader.rb:98:in `each'
	from /Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/config/loader.rb:98:in `block in load'
	from /Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/config/loader.rb:95:in `each'
	from /Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/config/loader.rb:95:in `load'
	from /Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/environment.rb:265:in `config_global'
	from /Applications/Vagrant/embedded/gems/gems/vagrant-1.4.3/lib/vagrant/environment.rb:519:in 

Open in new window

need to know how get path to MyDocuments folder using C++ ?  I'm not looking for syntax of VS but some thing that can be used in all IDE. I'll create binary file and will save it after creation in MyDocuments folder.

What is difference in defining string like 2 below methods:

1)  std::string str = "Test string";

2)   char* cstr = "Test string";

What is difference and which one is better approach.


I m developing a application which do tasks like reading files from folder, do some mathematical calculations and generate some graphs(using a library which can generate 3d graphics but we did not decide library yet ).

My concern is that if we use Microsoft Visual Studio for all tasks and use visual studio functions for graph then do u think that application can be modified using Eclipse ??

Is it possible to modify c++ application among tools like Eclipse and Visual Studio? Actually, my task will be integrated with someone else task but I am not sure what tool he is using.

Please advise.







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.