Questions tagged [sstream]

111 questions
0
votes
0 answers

Testing for number failing with std::istringstream

I'm trying to ask the user to enter a number, repeatedly until they do. The code below runs fine if user enters a number on the first try. However if they enter a non numeric character first, then a number, the loop never breaks as I would…
Eon
  • 149
  • 8
0
votes
4 answers

g++ Compile error: missing ';'

I am trying to run this code tResults = itos(Freq)+"\t"dtos(maxTemp)+"\t"+dtos(xB * FP.parU[1])+"\t"+dtos(xH * FP.parI[1])+"\t"+dtos(FP.parI[1]); string MaxResults::itos(int i) { stringstream s; s << i; return s.str(); } string…
mrswmmr
  • 2,081
  • 5
  • 21
  • 23
0
votes
3 answers

C++: Reading a line as : 'string string;int'

I have started coding lately(school curriculuim) and ran into a little problem. I want to read a .txt file, the lines are like "firstname lastname;phonenumber". ifstream file("names.txt"); string line, fname, lname; int num; while…
hemmy
  • 3
  • 2
0
votes
2 answers

sstream string wrong output

I am trying to read a string of three number using sstream but when I try to print them, I am getting a wrong output with four numbers. Code: #include #include using namespace std; int main() { string a("1 2 3"); …
Deep
  • 616
  • 1
  • 9
  • 17
0
votes
2 answers

How to seperate data from a file stream in c++

I just started learning c++ in college and for our first project we are asked to create a five function calculator (+, -, *, /, %) that reads input from a file, performs the arithmetic operation on it and outputs it to the screen. I am given an…
Tijani
  • 133
  • 2
  • 3
  • 16
0
votes
2 answers

How to assign results from std:fixed << setprecision(5) to variable in c++

Couldn't find an answer for following question: I'm new to C++ and am doing some tests now. I'm using std::fixed and std::setprecision functions to get a decimal number with 5 zeros. This works using cout, but i have no idea how to assigning the…
Esocoder
  • 1,032
  • 1
  • 19
  • 40
0
votes
1 answer

convert a string to chars and ints (a combination) with istringstream

I think that there's some trivial very silly bug, but i can't nail it. Any advice? string stuff = "5x^9"; istringstream sss(stuff); double coeff; char x, sym; int degree; sss >> coeff >> x >> sym >> degree; cout << "the coeff " << coeff <<…
alienflow
  • 400
  • 7
  • 19
0
votes
1 answer

serialize std::map using sstream

I'm working on serialising std::map using sstream in C++. Serialising function: template std::string serializeMap(const std::map& v){ std::stringstream ss; std::for_each(v.begin(), v.end(), [&ss](const…
Jishnu U Nair
  • 512
  • 5
  • 12
  • 29
0
votes
2 answers

Converting strstream to sstream conflict about c_str()

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,…
0
votes
0 answers

Error: Function stoi Not Declared (-std=c++11 is Enabled)

I'm using Code::Blocks 16.01 on Windows 10. I need to convert a string to an integer. So I'm trying to use stoi, but it says it's not declared. I have enabled -std=c++11 in compiler settings but it still gives me an error: 'stoi' was not declared in…
luffy
  • 105
  • 8
0
votes
1 answer

Custom ostream without flushing?

Currently I create an ostream with a custom stringbuf derived object, but it uses sync() to print text on the screen. Is there a way to avoid having to flush it? I really want to do logStream << "Test"; without std::flush or endl.
Jookia
  • 6,544
  • 13
  • 50
  • 60
0
votes
2 answers

C++ extracting ints from a string

I'm trying to extract integers from a string, for example user input could be 5ft12in or 5'12"`. However, the code works when my input is 5ft1in, but not when it is 5ft12in. I want to loop through the whole string and extract 3 numbers, as…
Dana Amin
  • 93
  • 1
  • 1
  • 9
0
votes
0 answers

C++ String parse of white spaces

I have this simple function that parses a sentence into a vector of strings. It works, despite the fact I can't make it user driven and have to set src manually. No, this is not homework, I'm willfully creating a scripting language. int…
user3337705
0
votes
1 answer

Does stringstream initializing with big length buffer doubles memory usage

Suppose I have a buffer with length 100MB char[100*1024*1024]. I would like to use stringstream facilities on this buffer like format read so I defined a new stringstream ss(arr) using this array. So I would like to learn if my program uses 200MB in…
mustafa.yavuz
  • 1,274
  • 2
  • 21
  • 40
0
votes
0 answers

Why local variable of type "ostringstream" is getting error messages for things that should be valid

Here is my code: % cat ch.cpp using namespace std; #include #include #include typedef const char* cstring; class GameCharacter { private: string desc; string name; string chid; public: …
A. P. Damien
  • 376
  • 2
  • 10