Decimal points with std::stringstream?

I think that your problem is that precision() sets the precision used in future stream insertion operations, not when generating the final string to present. That is, by writing ta << a; tb << b; tc << c; ta.precision(2); tb.precision(2); tc.precision(2); You’re setting precision too late, as the first three lines have already converted the … Read more

How to read file content into istringstream?

std::ifstream has a method rdbuf(), that returns a pointer to a filebuf. You can then “push” this filebuf into your stringstream: #include <fstream> #include <sstream> int main() { std::ifstream file( “myFile” ); if ( file ) { std::stringstream buffer; buffer << file.rdbuf(); file.close(); // operations on the buffer… } } EDIT: As Martin York remarks … Read more

Why doesn’t `std::stringstream::stringstream(std::string&&)` exist?

There’s history, which is disappointing. But also a future that looks bright. When move semantics went into C++11, it was huge, controversial, and overwhelming. I wanted to be able to move strings into and out of stringstream. However the politics at the time demanded that the internal store did not have to be a basic_string<charT>. … Read more

std::stringstream vs std::string for concatenating many strings

There’s no reason to expect std::string‘s appending functions to be slower than stringstream‘s insertion functions. std::string will generally be nothing more than a possible memory allocation/copy plus copying of the data into the memory. stringstream has to deal with things like locales, etc, even for basic write calls. Also, std::string provides ways to minimize or … Read more

Why copying stringstream is not allowed?

Copying of ANY stream in C++ is disabled by having made the copy constructor private. Any means ANY, whether it is stringstream, istream, ostream,iostream or whatever. Copying of stream is disabled because it doesn’t make sense. Its very very very important to understand what stream means, to actually understand why copying stream does not make … Read more

StringStream in C#

You can use tandem of MemoryStream and StreamReader classes: void Main() { string myString; using (var stream = new MemoryStream()) { Print(stream); stream.Position = 0; using (var reader = new StreamReader(stream)) { myString = reader.ReadToEnd(); } } }

How to construct a std::string from a std::vector?

C++03 std::string s; for (std::vector<std::string>::const_iterator i = v.begin(); i != v.end(); ++i) s += *i; return s; C++11 (the MSVC 2010 subset) std::string s; std::for_each(v.begin(), v.end(), [&](const std::string &piece){ s += piece; }); return s; C++11 std::string s; for (const auto &piece : v) s += piece; return s; Don’t use std::accumulate for string concatenation, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)