Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit separator in C++

Tags:

c++

How could I include a unit separator (value 31 in ascii table) in a string other than using snprintf()? I want to do like we normally initialize a string.

eg

char[100] a = "abc"
like image 830
Ashley Avatar asked Sep 17 '10 12:09

Ashley


1 Answers

31 in dec = 0x1f in hex. Therefore,

char x[] = "blah\x1f" "blah";
//              ^^^^ unit separator.

The string is split into two to avoid the compiler reading the escape sequence as 0x1fb (it should be read as 0x1f, which is 31 in decimal). Alternatively you could use octal sequence:

char x[] = "blah\037blah";
//              ^^^^ unit separator.
like image 85
kennytm Avatar answered Oct 02 '22 01:10

kennytm