Bellatrix
Enthusiast
Hello all. Today I thought I would make a small tutorial on Backslashes, special characters and the importance of them.
So let's start with a basic set of code.
Many of you already may know this small feature but here it is. Adding 2 slashes before any line of code will make the compiler read the code as a comment, or code that can only be seen in the source code. So if you were to run the program right now with two slashes before a set of code, it would not read the code, and it would be ignored. So let's put 2 slashes before any code.
Running the program you should see;
Why hello thereeee.
And the 2 slashes will not affect the code, and it will be ignored.
Another great affect of the backslash is that it can also create tabs. "What do you mean?" I'll show you.
So let's have the basic code once again, but this time let's add a backslash and "T" and run the compiler.
Running the compiler you should see this:
See? Adding a /t before any set of text will add a tab to the text before it. Neat right? There's more.
What if you wanted to add just one backslash to the text between cout? You would add 2 backslashes.
running the code you should see this.
It only excecuted ONE backslash. There is still one more neat tutorial. Let's say you wanted to make a double quote INSIDE the double quotes. How would we do that? Simple. Add a backslash before the double quotes.
Running the code you should see this.
Why hello thereeee. "
Cool right? Cool effects of the backslash Hope you enjoyed my tutorial, and please give feedback
So let's start with a basic set of code.
Code:
#include <iostream>
using namespace std;
int main()
{
cout << "Why hello thereeee. " << endl;
return 0;
}
Many of you already may know this small feature but here it is. Adding 2 slashes before any line of code will make the compiler read the code as a comment, or code that can only be seen in the source code. So if you were to run the program right now with two slashes before a set of code, it would not read the code, and it would be ignored. So let's put 2 slashes before any code.
Code:
#include <iostream>
using namespace std;
//two slashes before code.
int main()
{
cout << "Why hello thereeee. " << endl;
return 0;
}
Running the program you should see;
Why hello thereeee.
And the 2 slashes will not affect the code, and it will be ignored.
Another great affect of the backslash is that it can also create tabs. "What do you mean?" I'll show you.
So let's have the basic code once again, but this time let's add a backslash and "T" and run the compiler.
Code:
#include <iostream>
using namespace std;
int main()
{
cout << "Why/thello thereeee. " << endl;
return 0;
}
Running the compiler you should see this:
Why hello thereeee.
See? Adding a /t before any set of text will add a tab to the text before it. Neat right? There's more.
What if you wanted to add just one backslash to the text between cout? You would add 2 backslashes.
Code:
#include <iostream>
using namespace std;
int main()
{
cout << "Why hello //thereeee. " << endl;
return 0;
}
running the code you should see this.
Why hello /thereeee.
It only excecuted ONE backslash. There is still one more neat tutorial. Let's say you wanted to make a double quote INSIDE the double quotes. How would we do that? Simple. Add a backslash before the double quotes.
Code:
#include <iostream>
using namespace std;
int main()
{
cout << "Why hello thereeee. /" << endl;
return 0;
}
Running the code you should see this.
Why hello thereeee. "
Cool right? Cool effects of the backslash Hope you enjoyed my tutorial, and please give feedback