escape sequence in string

J

Jim Langston

I want to build a string that contains the character 1, followed by ABC
followed by the characters 255 255. One would think it would be simple:

std::string Data( "\x01ABC\xFF\xFF", 6);
but that doesn't compile. It says:
error C2022: '6844' : too big for character

At first I wondered where the heck it got 6844 then I realized. It took the
excape sequence as \x01ABC since A, B and C are valid hexidecimal digits.
So I tried
std::string Data( "\x0001ABC\xFF\xFF" );
but same error. How do I get the compiler to stop treating characters as
hex digits but part of the data? I know I could break up the string
something like:
std::string Data("\x01", 1 );
Data += "ABC\xFF\xFF";
but that seems like an extra step I really don't need (or do I)?
 
O

ondra.holub

There is no limit, how many hex characters should be considered. But
you can deal with it this way:

std::string s("\x1" "ABC");
 
T

terminator

I want to build a string that contains the character 1, followed by ABC
followed by the characters 255 255. One would think it would be simple:

std::string Data( "\x01ABC\xFF\xFF", 6);
but that doesn't compile. It says:
error C2022: '6844' : too big for character

At first I wondered where the heck it got 6844 then I realized. It took the
excape sequence as \x01ABC since A, B and C are valid hexidecimal digits.
So I tried
std::string Data( "\x0001ABC\xFF\xFF" );
but same error. How do I get the compiler to stop treating characters as
hex digits but part of the data? I know I could break up the string
something like:
std::string Data("\x01", 1 );
Data += "ABC\xFF\xFF";
but that seems like an extra step I really don't need (or do I)?
try this:
"str1""str2""str3"
compiler automatically concates the 3 strings into 1 at compile time
 
B

BobR

Jim Langston wrote in message ...
I want to build a string that contains the character 1, followed by ABC
followed by the characters 255 255. One would think it would be simple:

std::string Data( "\x01ABC\xFF\xFF", 6);
but that doesn't compile. It says:
error C2022: '6844' : too big for character

At first I wondered where the heck it got 6844 then I realized. It took the
excape sequence as \x01ABC since A, B and C are valid hexidecimal digits.
So I tried
std::string Data( "\x0001ABC\xFF\xFF" );
but same error. How do I get the compiler to stop treating characters as
hex digits but part of the data? I know I could break up the string
something like:
std::string Data("\x01", 1 );
Data += "ABC\xFF\xFF";
but that seems like an extra step I really don't need (or do I)?


(answered already, but...) Don't forget:

std::string Chars;
Chars.push_back( char( 01 ) );
Chars.push_back( char( 'A' ) );
Chars.push_back( char( 254 ) );
Chars.push_back( char( 255 ) );
Chars.push_back( char( 0xFF ) );
Chars.at( 2 ) = char( 0x0C );

.... just in case you need it.
 
J

Jim Langston

BobR said:
Jim Langston wrote in message ...


(answered already, but...) Don't forget:

std::string Chars;
Chars.push_back( char( 01 ) );
Chars.push_back( char( 'A' ) );
Chars.push_back( char( 254 ) );
Chars.push_back( char( 255 ) );
Chars.push_back( char( 0xFF ) );
Chars.at( 2 ) = char( 0x0C );

... just in case you need it.

Thanks, yeah, knew about that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top