I have been learning the Old C++ standard in my
school. I knew of the new C++11 standard but didn't start learn it until now. But I can't get any of my programs to run. I use the g++ compiler on a Linux Ubuntu system. I tried various methods to for my programs to show the output including ''getch ()'' method using the conio.h file but it isn't included in the new standard. I also tried "system ("PAUSE"); " and the cin.get method. None work. The program compiles and produces an "a.out" file but it doesn't open. I have very less knowledge of the gnu compiler as we used an ancient Borland Turbo IDE in school. Can anyone help me with how to get the programs to run. Also my prime focus is Web development and I would like to know how C++ can be used in Web development if it can. Thank you.
are you building classes or is this a C procedural program? if it is a c++ class that creates an object then you need to put C guards around the C code. See below for the syntax of adding guards. this is because the compiler will try to mangle the symbols into C++. Sometimes the compiler is forgiving but often it is not. if you are building an object, I would recommend this code.
1 2 3 4 5 6 7 8 9 10 11 12
//// H file foo.h
void bar() const;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
////CPP file foo.cpp
// you can bring in the entire std namespace by calling using namespace std;
// However I prefer to be very specific to the facility I need.
// that way I don't get more clutter in the program namespace than needed.
// a place to wait for a char input. example is y/n as an answer to a prompt using cout.
cin >> answer; ///< wait for console input from stdin
//do something with response.
cout << answer; ///< simple print answer to stdout
Firstof all, get yourself a modern compiler. GCC 4.8's g++ is a good choice and so is Clang's clang++.
As for the code to keep the terminal open, you could just add a:
1 2 3 4 5 6
// your code here
When it comes to C++ Web Frameworks I think "Wt" is the most common and one that's well maintained.
As of the:
I would refrain from using any form of system() call, as it is slow and not considered good practice. It spawns a separate process (as in program) and therefor will be a possible point of memory leak in your code if something bad happens before the control is returned to your program.