I have a set of strings set<string> aSet
. How to convert the set to just a string a have all the elements separated by a comma? Thank you!
What Is stoi() in C++? In C++, the stoi() function converts a string to an integer value. The function is shorthand for “string to integer,” and C++ programmers use it to parse integers out of strings. The stoi() function is relatively new, as it was only added to the language as of its latest revision (C++11) in 2011.
This LPCWSTR is Microsoft defined. So to use them we have to include Windows. h header file into our program. To convert std::wstring to wide character array type string, we can use the function called c_str() to make it C like string and point to wide character string.
std::wstring is used for wide-character/unicode (utf-16) strings. There is no built-in class for utf-32 strings (though you should be able to extend your own from basic_string if you need one).
Solution: Use sprintf() function. You can also write your own function using ASCII values of numbers.
Here's one option:
std::ostringstream stream;
std::copy(aSet.begin(), aSet.end(), std::ostream_iterator<std::string>(stream, ","));
std::string result = stream.str();
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