Compiler Error C2001
newline in constant
A string constant cannot be continued on a second line unless you do the following:
End the first line with a backslash.
Close the string on the first line with a double quotation mark and open the string on the next line with another double quotation mark.
Ending the first line with \n is not sufficient.
Examples
The following sample generates C2001:
// C2001.cpp
// C2001 expected
#include <stdio.h>
int main()
{
printf_s("Hello,
world");
printf_s("Hello,\n
world");
}
Spaces at the beginning of the next line after a line-continuation character are included in the string constant. None of the examples shown above embed a newline character into the string constant. You can embed a newline character as shown here:
// C2001b.cpp
#include <stdio.h>
int main()
{
printf_s("Hello,\n\
world");
printf_s("Hello,\
\nworld");
printf_s("Hello,\n"
"world");
printf_s("Hello,"
"\nworld");
printf_s("Hello,"
" world");
printf_s("Hello,\
world");
}
Pripomienky
https://aka.ms/ContentUserFeedback.
Pripravujeme: V priebehu roka 2024 postupne zrušíme službu Problémy v službe GitHub ako mechanizmus pripomienok týkajúcich sa obsahu a nahradíme ju novým systémom pripomienok. Ďalšie informácie nájdete na stránke:Odoslať a zobraziť pripomienky pre