Thursday, October 22, 2015

Problem 1: When executing a program from the IDE, the console window blinks and then closes immediately.
Answer 1: Some compilers (eg. Bloodshed’s Dev C++) don’t automatically pause the console screen after the program has finished executing. If this is the case with your compiler, the following two steps will fix your problem:


First, add the following line near the top of your program:
Second, add the following code at the end of the main() function (right before the return statement):
This will cause your program to wait for you to press a key before continuing, which will give you time to examine your program’s output before your compiler closes the console window.
Other solutions, such as the commonly suggested system("pause") solution may only work on certain operating systems and should be avoided.
Note: Visual Studio will not pause at the end of a console application if it is run with debugging (Debug Menu->Start Debugging). If you want it to pause, you can either use the code solution above, or run your program without debugging (Debug Menu->Start Without Debugging).
Problem 2: When compiling with Microsoft Visual C++, you get the following error: “c:vcprojectstest.cpp(263) :fatal error C1010: unexpected end of file while looking for precompiled header directive”
Answer 2: This error occurs when the Microsoft Visual C++ compiler is set to use precompiled headers but one (or more) of your C++ code files does not include the stdafx header as the first line. To fix this problem, simply locate the file(s) producing the error (in the above error, test.cpp is the culprit), and add the following line at the very top of the file(s):
Note that for programs with multiple files, every C++ code file needs to start with this line.
Alternatively, you can turn off precompiled headers.

Problem 3: When trying to use cin, cout, or endl, the compiler says cin, cout, or endl is an “undeclared identifier”
Answer 3: First, make sure you have included the following line near the top of your file:
Second, make sure cin, cout, and endl are prefixed by “std::”. For example:

A few common C++ problems

  • Uploaded by: Unknown
  • Views:
  • Category:
  • Share

    0 comments:

    Post a Comment

     

    Our Team Members

    Original Theme 2015 VIDEO- | Designed by EmcCadch3