C++ printing boolean, what is displayed?

The standard streams have a boolalpha flag that determines what gets displayed — when it’s false, they’ll display as 0 and 1. When it’s true, they’ll display as false and true. There’s also an std::boolalpha manipulator to set the flag, so this: …produces output like: For what it’s worth, the actual word produced when boolalpha is set to true is localized–that is, <locale> has a num_put category that handles numeric conversions, … Read more

undefined reference to ‘std::cout’

Compile the program with: as cout is present in the C++ standard library, which would need explicit linking with -lstdc++ when using gcc; g++ links the standard library by default. With gcc, (g++ should be preferred over gcc)

‘cout’ was not declared in this scope

Put the following code before int main(): And you will be able to use cout. For example: Now take a moment and read up on what cout is and what is going on here: http://www.cplusplus.com/reference/iostream/cout/ Further, while its quick to do and it works, this is not exactly a good advice to simply add using namespace std; at the top … Read more

‘cout’ was not declared in this scope

Put the following code before int main(): And you will be able to use cout. For example: Now take a moment and read up on what cout is and what is going on here: http://www.cplusplus.com/reference/iostream/cout/ Further, while its quick to do and it works, this is not exactly a good advice to simply add using namespace std; at the top … Read more

How do I print out the contents of a vector?

If you have a C++11 compiler, I would suggest using a range-based for-loop (see below); or else use an iterator. But you have several options, all of which I will explain in what follows. range-based for-loop (C++11) In C++11 (and later) you can use the new range-based for-loop, which looks like this: The type char … Read more