Bold Aesthetic Creative Games

An Indie Game Studio Developing Bold, Aesthetic & Creative Video Games

C++ Programming Series: Special Characters

C++ Programming Series: Special Characters

In the previous post, we talked about some really important but useless kind of things. I mean that why you really need to understand precedence and sizeof()!

Well, this post is also not interesting but I believe that it is worth knowing! For example, can you please tell me how to show a double quote on the console? Ok, so here is the code which may do that:

cout << "You said, "I can show a double quote on the console!" and this is the code which may do that!" << endl;

What happens? Got an error! This is because you divided the sentence into strings… And strings are represented by the group of characters between two double-quotes.

Similarly, you may want to have a single quote and then, a tab instead of a group of spaces for proper indentation. For the very purpose, there are some special characters. The list is mentioned here.

The solution of the double quote problem gets a fix below:

cout << "You said, \"I can show a double quote on the console!\" and this is the code which may do that!" << endl;

Instead of endl, you could have \n:

cout << "The special characters are very useful!\n";

No matter how many digits a number has in a list of numbers, it will be formatted fine with /t:

cout << " 1.\t73\n 2.\t9\n 3.\t992\n 4.\t14\n"; //Just run that to find out its meaning!

That’s it! Try to use all kinds of special characters and make them run as you want!

Believe me, it’s really good to know these characters…

Leave a Reply

Your email address will not be published. Required fields are marked *