Strings between quotation marks in C++ [duplicate] - c++

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What do single quotes do in C++ when used on multiple characters?
The following code compiles in C++:
unsigned int x;
x = 'abc';
What does it mean? Is putting string between quotation marks legal? What does it do?

Is not a string, but a multi character literal. See What do single quotes do in C++ when used on multiple characters?. (Vote to close as duplicated)

Related

How do i "subtract" a character from a string in c++ [duplicate]

This question already has answers here:
Remove last character from C++ string
(12 answers)
Closed 8 months ago.
Lets say I have a string variable with the value "bananas" in it. I want to subtract the last letter so the string becomes "banana". I am quite a newbie, so I dont even know how to tackle this.
Just use the pop_back() function.
Try this code, it 'subtracts' the last character:
std::string str = "bananas";
str.pop_back();

regex to grab int/floats and exclude text [duplicate]

This question already has answers here:
RegEx for both, integer and float [closed]
(3 answers)
Closed 4 years ago.
trying to write the appropriate regex expression to capture barometric pressure with two string possibilities. looking to simply grab the float values and remove the "in" string.
The String possibilities are (examples):
'30.01in'
or
'30in'
my current expression (see below) works for the former (30.01), but fails to grab the float in the latter (30in)
re.compile('[0-9]?[0-9]\...')
(\d+(?:\.\d+)?)in
This should capture ints or floats

Find sequence of chars in string c++ and erase it [duplicate]

This question already has answers here:
Replace part of a string with another string
(17 answers)
Closed 6 years ago.
I need find all occurrences of sequence: \r\n(some hex number)\r\n and delete this sequences from my string. Hexadecimal number doesn't start with 0x or x. It's just 20bb for example.
These sequences are chunks in http 1.1 protocol. I can't find them with string.find, maybe some regex would help.
Thanks for help.
From the code here I made this:
std::string string("\r\n20BB\r\n");
string = std::regex_replace(string,
std::regex("\r\n[0-9A-Fa-f]+\r\n"), "");
It should work. The [0-9A-Fa-f]+ captures one or more hex digits.

Is there something equivelant in c++(or c++11) for # like in c#? [duplicate]

This question already has answers here:
What is the C++ equivalent of the C# # symbol prefixing strings?
(3 answers)
Closed 9 years ago.
In C# we can define a complicated string with #:
string str = #"This is the first line.\r\nThis is still the first line";
how about in C++? if we have something like this we don't need to use converting sign '\' for all the special characters.
In C++11 (only) you can use a raw string literal:
std::string str = R"(This is the first line.\r\nThis is still the first line)";

How does C++ understand two letter characters [duplicate]

This question already has answers here:
Multicharacter literal in C and C++
(6 answers)
What do single quotes do in C++ when used on multiple characters?
(5 answers)
Closed 9 years ago.
C++ seems to allow up to four characters to be held in single quotes, such as:
char c = 'abcd';
but at runtime, only the last value ('d') seems to be actually stored away. This behavior seems to happen for pairs of two, three, or four (at five the compiler finally calls uncle). But what's the deal with this design? I don't really see the logic in it.