I really did not find an answer that is close ...
the opposite way is pretty simple as str [0]
But I need to drop only 1 char per line ...
like this:
char c = 34; string(1,c); //this doesn't work, the string is always empty. string s(c); //also doesn't work. boost::lexical_cast<string>((int)c); //also return null
All
string s(1, c); std::cout << s << std::endl;
and
std::cout << string(1, c) << std::endl;
string s; s.push_back(c); std::cout << s << std::endl;
worked for me.
I honestly thought that the casting method would work fine. Since you cannot try stringstream. The following is an example:
#include <sstream> #include <string> stringstream ss; string target; char mychar='a'; ss << mychar; ss >> target;