Why can I display every character in quotations with std::cout?

When I run this, the "\" doesn't show. How come?

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;

int main ()
{
cout << "   /\ " <<endl;
cout << "  /__\ " <<endl;
cout << " /    \ " <<endl;

 return 0;
}
Last edited on
@WowICantProgram

The '\' character is special. To show one on screen, you must use two of them, side-by-side, as in '\\'. As you may have seen in other programs, you can use '\n' for a newline, '\t' as a tab, a '\b' to back the cursor one space, a '\"' to show a quote and a few others. Try it in your program, and see the results.
@whitenite1

Ah, I see. Thanks for the reply. '\\' fixed everything, I thought the quotations would be enough to remove the traits that '\' has.
Last edited on
'"' and "'" don't require slashes, whereas "\"" and '\'' do.
In C++11 you can use raw string literals to avoid escaping characters:
1
2
3
4
5
6
7
8
9
#include <iostream>

int main ()
{
    std::cout << R"(
  /\
 /__\
/    \ )";
}

  /\
 /__\
/    \
Topic archived. No new replies allowed.