创建、连接和转换字符串
How to do it...
#include <iostream> #include <string> #include <string_view> #include <sstream> #include <algorithm> using namespace std; using namespace std::literals;int main() { string a { "a" }; auto b ( "b"s );string_view c { "c" }; auto d ( "d"sv );cout << a << ", " << b << '\n'; cout << c << ", " << d << '\n';cout << a + b << '\n'; cout << a + string{c} << '\n';ostringstream o; o << a << " " << b << " " << c << " " << d; auto concatenated (o.str()); cout << concatenated << '\n';transform(begin(concatenated), end(concatenated), begin(concatenated), ::toupper); cout << concatenated << '\n'; }$ ./creating_strings a, b c, d ab ac a b c d A B C D
How it works...
Last updated