How can write out rep sign (\) ?
cout << "???";
The answers from , and are correct: the backslash is the language escape character, so a source literal needs special treatment. For completeness and for readers using newer C++ standards or working with paths/escaped formats, a few alternative approaches and caveats follow.
Raw string literals (C++11+) let backslashes appear literally inside the source without doubling, which is handy for Windows paths or regexes. See the C++ reference on raw string literals for details and restrictions: Raw string literals.
std::cout << R"(C:\Program Files\MyApp\app.exe)"; Writing the character by its numeric code or using stream put avoids escape syntax in the literal itself (useful in generated code or when the value comes from data):
std::cout.put(char(92)); // decimal 92
std::cout.put(0x5C); // hex 5C When constructing file paths programmatically, prefer std::filesystem::path (C++17+) or forward slashes on platforms that accept them; this reduces manual escaping and platform issues. Additional caution: formats that embed strings (JSON, regex, CSV, shell commands) often require extra layers of escaping, so double-check the target format’s rules before emitting backslashes. Relevant references: Escape sequences and std::filesystem::path.
Jump to Post— Radical Edward 301std::cout << "\\";
std::cout << "\\"; the character '\' ? it would be
cout<<'\\'<<endl; //just the single character
cout<<"c:\\someFile"<<endl; //used as part of a string
//second prints to console "c:\someFile" edit: ..... beaten to the punch again :'( lols
string str="\\"; We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.