Solutions to the Most Common C++ Programming Problems

Solutions to the Most Common C++ Programming Problems

As we discuss in this lesson, beginner programmers often run into problems when creating programs in C++.

Problem # 1

How to use Cyrillic in C ++ programs?

Answer # 1

To display the Cyrillic alphabet in C++, you need to include the <Windows.h> header file:

In the main() function, write the following two lines:

As an alternative, you can use the following line in the main () function:

Problem # 2

When the program is executed, a black console window appears and then disappears immediately.

Answer # 2

Depending on the compiler you are using (for example, Bloodshed’s Dev C++), the console window may not be delayed after the program has been completed. In the case that the problem is in the compiler, then the following steps will fix it:

The first step is to add the following line of code to your program:

In Step # 2, add the following code (just before the return statement) to the end of the main () function:

A keypress closes the console window, so the program will wait for it to be pressed. During extra time, you can look over/study your notes carefully. The console window will close with any keypress.

The above option is preferable to alternatives such as a system(“pause”);, which may only be compatible with certain operating systems.

Problem # 3

When using cin, cout, or endl, the compiler says they are ” undeclared identifiers”.

Answer # 3

To begin with, ensure that the following lines of code appear at the top of your program:

Make sure that cin, cout, and endl are prefixed with std::, for example:

Problem # 4

When using endl to branch to a new line, an error appears that end1 is an “undeclared identifier”.

Answer # 4

Don’t confuse the letter l (lowercase L) in the endl of the sentence with the number 1. In the endl all of the symbols are letters. It is also easy to confuse the capital letter О with a number 0(zero).

Problem # 5

My program compiles but doesn’t work as expected. What should I do?

Answer # 5

The program needs to be debugged. In next lessons you will learn more about this topic.

Problem # 6

What is the procedure for enabling line numbers in Visual Studio?

Answer # 6

Navigate to the menu “Tools> Options”:

Open the tab  “Text Editor> All Languages> General” Check the box next to “Line numbers”, then click “ОК”:

Problem # 7

This error appears when I compile the program: “Unresolved external symbol _main or _WinMain @ 16”.

Answer # 7

As a result, your compiler cannot find the main() function. There should be a function like this in every program.

The following points should be checked:

  •   Does your program contain a function called main()?
  • Does the word main appear correctly spelled?
  •  In your project, is the file that contains the function included in main()? This file must be part of your project if the function main() does not exist in it (if not, add it to your project)
  • When compiling the program, does the file that contains the function get included in the main()?

Problem # 8

I receive the following warning when attempting to compile the program: “The PDB file could not be found or opened.”

Answer # 8

There is no error here, only a warning. This change will not affect program performance. However, in Visual Studio, you can solve everything like this: go to the menu “Debug> Options> Debug> Symbols” and check the box next to “Microsoft Symbol Servers”, then click “ОК”.

Problem number 9

I use a combination of Code:: Blocks and G ++, however, C++ 11 / C++ 14 functionality does not work.

Answer # 9

You can check the box next to the item “Have g++ follow C++14 ISO C++ language standard” in Code:: Blocks by going to “Project” > “Build options” > “Compiler settings” > “Compiler flags”. This can be seen in Lesson 4, where screenshots accompany the lesson.

In G++, the following code needs to be added to the command line:


Problem # 10

When I run the program, a console window appears, but no output is generated.

Answer # 10

Antivirus software can prevent your program from running. Run the program again after disabling it for a while.

I am having another problem that I cannot figure out. I would like to get an answer, but where can I find it?

These lessons will undoubtedly result in questions or problems for you. Are you aware of what to do?

Google is your first port of call. Give your problem a clear formulation so that it can be Googled. Using the quote symbol, paste an error message into Google search. Probably someone else has asked and answered a question like yours.

Ask on specialized Q / A services, or on forums dedicated to programming / IT topics if Google didn’t work. Here are some of the most popular:

  •    Stack Overflow
  •    CyberForum
  •    Habr Q&A (formerly Toster)

Please be specific about your problem and indicate what operating system and IDE you are using, as well as what you have already attempted to solve it.


Please enter your comment!
Please enter your name here