I want to store CTRL–A (0x01) in a C++ string. Tried the following, but it does not work. Could you tell what I am missing here?
string s = "\u0001";
I get the error when compiled in g++:
error: \u0001 is not a valid universal character
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The error you get is due to 2.2/2 in C++03:
So, for a string literal you have to use
\x1or\1instead (and you can add leading zeroes to taste). Alternatively if you do only want one character in your string:or:
The restriction is relaxed in C++11 (2.3/2):