sstream

sstream redeclared with public access compiler error

拟墨画扇 提交于 2019-12-24 04:29:05
问题 I came across this error when running make on a large project using gcc5.4.0. /usr/include/c++/5/sstream:300:14: error: '__xfer_bufptrs' redeclared with 'public' access struct __xfer_bufptrs ^ /usr/include/c++/5/sstream:67:14: note: previously declared 'private' here struct __xfer_bufptrs; To me it seems like an issue with the compiler? Since the issue arises in a standard c++ library sstream? It does not make sense to me, am I using a wrong compiler? Here are the code snippets the error

What exactly does stringstream do?

两盒软妹~` 提交于 2019-12-17 06:21:54
问题 I am trying to learn C++ since yesterday and I am using this document:http://www.cplusplus.com/files/tutorial.pdf (page 32) . I found a code in the document and I ran it. I tried inputting Rs 5.5 for price and an integer for quantity and the output was 0. I tried inputting 5.5 and 6 and the output was correct. // stringstreams #include <iostream> #include <string> #include <sstream> using namespace std; int main () { string mystr; float price = 0; int quantity = 0; cout << "Enter price: ";

Not getting all lines from a text file when using getline() in C++

冷暖自知 提交于 2019-12-11 20:35:28
问题 I was given a homework assignment to generate a txt file containing a random number of lines, each with a random amount of integers, ranging between a minimum value and a maximum value. Lots of rand() fun. In any case, that was the easy part. The second part of the problem is to read over the first file and create a second file that contains some statistics, such as: the sum of all integers in the file, their average, min and max values, and my main issue: the sum of all integers in each line

How do I use the ostringstream properly in c++?

独自空忆成欢 提交于 2019-12-09 14:21:30
问题 I am attempting to return some information when my toString() method is called, which include an integer and some floats. I learned about ostringstream works great but when the class that contains this method is called over and over again, the information gets stacked onto my previous output. Here is my code ostringstream int_buffer, float_buffer, float_buffer2; is introduced at the beginning of my class, then string toString() { int_buffer << on_hand; float_buffer << price; float_buffer2 <<

Why is stringstreams rdbuf() and str() giving me different output?

大憨熊 提交于 2019-12-09 13:24:48
问题 I have this code, int main() { std::string st; std::stringstream ss; ss<<"hej hej med dig"<<std::endl; std::getline(ss,st,' '); std::cout <<"ss.rdbuf()->str() : " << ss.rdbuf()->str(); std::cout <<"ss.rdbuf() : " << ss.rdbuf(); return 0; } Giving me this output ss.rdbuf()->str() : hej hej med dig ss.rdbuf() : hej med dig But why is that? Is that because of ostreams definition of operator<str() gives me different output. In my eyes the output should be the same even if I have used getline. 回答1

Converting strstream to sstream conflict about c_str()

蹲街弑〆低调 提交于 2019-12-04 06:02:08
问题 I have this code block as written with strstream . And I converted it to sstream as below. I'm not sure, but I think printStream->str() is returning a string object with a copy (temporary) of the contents in the stream buffer pointed by printStream , and then then you are invoking c_str() on it and getting a const char * , and then casting away the const-ness, and then returning the pointer outside the function scope. I think since its a temporary value you are getting back from printStream-

How do I use the ostringstream properly in c++?

那年仲夏 提交于 2019-12-03 23:30:17
I am attempting to return some information when my toString() method is called, which include an integer and some floats. I learned about ostringstream works great but when the class that contains this method is called over and over again, the information gets stacked onto my previous output. Here is my code ostringstream int_buffer, float_buffer, float_buffer2; is introduced at the beginning of my class, then string toString() { int_buffer << on_hand; float_buffer << price; float_buffer2 << generated_revenue; string stron_hand = int_buffer.str(); string strprice = float_buffer.str(); string

How to parse complex string with C++?

此生再无相见时 提交于 2019-12-03 06:06:44
问题 I'm trying to figure out how could I parse this string using " sstream " and C++ The format of it is: "string,int,int". I need to be able to assign the first part of the string which contains an IP address to a std::string. Here is an example of this string: std::string("127.0.0.1,12,324"); I would then need to obtain string someString = "127.0.0.1"; int aNumber = 12; int bNumber = 324; I will mention again that I can't use boost library, just sstream :-) Thanks 回答1: Here's a useful

What exactly does stringstream do?

时光毁灭记忆、已成空白 提交于 2019-11-26 23:30:39
I am trying to learn C++ since yesterday and I am using this document: http://www.cplusplus.com/files/tutorial.pdf (page 32) . I found a code in the document and I ran it. I tried inputting Rs 5.5 for price and an integer for quantity and the output was 0. I tried inputting 5.5 and 6 and the output was correct. // stringstreams #include <iostream> #include <string> #include <sstream> using namespace std; int main () { string mystr; float price = 0; int quantity = 0; cout << "Enter price: "; getline (cin,mystr); stringstream(mystr) >> price; cout << "Enter quantity: "; getline (cin,mystr);

Use an Anonymous Stringstream to Construct a String

白昼怎懂夜的黑 提交于 2019-11-26 21:53:45
问题 I want to read directly into a string with code like this: std::string myString(( std::ostringstream() << myInt << " " << myFloat << " " << std::boolalpha << myBool ).str()); But VS2012 is giving me a complaint that basic_ostream doesn't have an str() method. Is there a way to do this with an anonymous stringstream? 回答1: The operator<< for streams returns std::ostream & which doesn't have str() member function. You need to use cast. static_cast<std::ostringstream&>(std::ostringstream() << etc