0

I want to get the output \\ ,so I type this to my code putchar('\\\'); but it doesn't work out ,and I get the following error

D:\c++ work\change\change.cpp(17) : error C2001: newline in constant
D:\c++ work\change\change.cpp(17) : fatal error C1057: unexpected end of file in macro expansion

why?

Deduplicator
  • 43,322
  • 6
  • 62
  • 109
zhenganyi
  • 169
  • 9

1 Answers1

5

\\ is an escaped \, then you have \' which is an escaped '. I'm guessing you meant to write: putchar('\\'); or putchar('\\\\'); (the latter being incorrect, you should do the former twice or use another function)

As you have it now (\\\) you're escaping the last ' which is causing your compiler to "misinterpret" your code. (I put misinterpret in quotes because it's actually interpreting it correctly, it's just not immediately obvious).

tl;dr

putchar('\\');
putchar('\\');

or

puts("\\\\");

will get you the correct output. (See live example)

Borgleader
  • 15,499
  • 5
  • 43
  • 61