Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a set of strings into a simple string c++ [closed]

Tags:

c++

string

set

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!

like image 858
ReeSSult Avatar asked Dec 03 '15 21:12

ReeSSult


People also ask

Can we use stoi in C?

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.

How do you convert Lpcwstr to string?

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.

What is Wstring?

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).

How can a number be converted to a string in C?

Solution: Use sprintf() function. You can also write your own function using ASCII values of numbers.


1 Answers

Here's one option:

std::ostringstream stream;
std::copy(aSet.begin(), aSet.end(), std::ostream_iterator<std::string>(stream, ","));
std::string result = stream.str();
like image 99
molbdnilo Avatar answered Oct 19 '22 21:10

molbdnilo