My question is related to the use of the "s" suffix in C++?
Example of code using the "s" suffix:
auto hello = "Hello!"s; // a std::string
The same could be written as:
auto hello = std::string{"Hello!"};
I was able to find online that the "s" suffix should be used to minimizes mistakes and to clarify our intentions in the code.
Therefore, is the use of the "s" suffix only meant for the reader of the code? Or are there others advantages to its use?
The std::string_view, from the C++17 standard, is a read-only non-owning reference to a char sequence. The motivation behind std::string_view is that it is quite common for functions to require a read-only reference to an std::string-like object where the exact type of the object does not matter.
C++ has in its definition a way to represent a sequence of characters as an object of the class. This class is called std:: string. String class stores the characters as a sequence of bytes with the functionality of allowing access to the single-byte character.
LF (character : \n, Unicode : U+000A, ASCII : 10, hex : 0x0a): This is simply the '\n' character which we all know from our early programming days. This character is commonly known as the 'Line Feed' or 'Newline Character'.
A wide string literal is a null-terminated array of constant wchar_t that is prefixed by ' L ' and contains any graphic character except the double quotation mark ( " ), backslash ( \ ), or newline character. A wide string literal may contain the escape sequences listed above and any universal character name.
Null characters can be included in the raw string trivially; example from http://en.cppreference.com/w/cpp/string/basic_string/operator%22%22s
int main() { using namespace std::string_literals; std::string s1 = "abc\0\0def"; std::string s2 = "abc\0\0def"s; std::cout << "s1: " << s1.size() << " \"" << s1 << "\"\n"; std::cout << "s2: " << s2.size() << " \"" << s2 << "\"\n"; }
Possible output:
s1: 3 "abc" s2: 8 "abc^@^@def"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With