Questions tagged [sstream]
111 questions
1
vote
1 answer
modify number of variables in istringstream
I need to get input in a line based on a modifiable number of variables that are determined from an earlier input.
If the input you get in an earlier function is 1, the the code would be like
std::string istring;
std::getline(std::cin,…

fishyperil
- 35
- 6
1
vote
2 answers
Is it possible to iterate through a text file lines and use stringstream to parse each line?
What I am trying to do is read from a text file each line while parsing using sstream library. I got the program to run but it's stuck in a loop.
Program:
string date;
int time;
float amount;
ifstream testFile("test.txt");
string token;
string…

Chuck
- 75
- 1
- 2
- 10
1
vote
2 answers
parsing an sstream
I am parsing a file which contains both strings and numerical values. I'd like to process the file field by field, each delimited by a space or an end-of-line character.
The ifstream::getline() operation only allows a single delimiting character.…

nbonneel
- 3,286
- 4
- 29
- 39
1
vote
3 answers
validation using sstream failing
cout << "\nPlease enter x-ordinate: ";
cin >> test;
stringstream ss(test);
ss >> x;
while(ss.fail())
{
ss.str("");
cin.clear();
cin.ignore(256, '\n');
cout << "Please enter integer: \n";
cin >> test;
stringstream ss(test);
ss >> x;
cout << x <<…

user6235245
- 61
- 6
1
vote
1 answer
C++ sstream skipping first three inputs from a file
I need to open a file in this format
Dat Nguyen 77.7 88.8 99.9 11.1 22.2
Pat Nguyen 2 3 4 5 6
I need to assign the first name of a line to a member array of structs and last name of the line to another member of the struct and each number of the…

Dat Nguyen
- 31
- 4
1
vote
3 answers
C++ reading in a file, ignoring commas and outputting data to the screen
I have a file in the format:
FirstName,MiddleName,LastName,Major,City,State,GPA
I'm trying to read in the file and output the data without the commas to the screen. This is what I have so far, but it only outputs the GPA's:
#include…

Jordan C
- 11
- 1
- 2
1
vote
2 answers
Misbehavior with istringstream conversions
When I try to extract valid numbers from an input using istringstream I get the follwoing misbehavior from istringstream:
For Example:
void extract(void)
{
double x;
string line, temp;
getline(cin, line);
istringstream is(line);
while(is…

Andy_A̷n̷d̷y̷
- 795
- 2
- 11
- 25
1
vote
2 answers
c++ sstream,reading different amount of variables per line
I am trying to read a text file with different amount of variables on each line and set the correct values to a vector using sstream.
/*Example file
"f 1 2 3"
"f 4 5 6 7" */
ifstream infile(file);
string line;
char a;
int…

user3085497
- 121
- 2
- 6
1
vote
1 answer
Receive Binary Data and Write (Socket Programming in C++)
i have created server and client to communication. Client sends binary data of image then server receives it and writes to file. I have pasted necessary code below.
std::stringstream binStr;
bytes_received = recv(new_sd,…

Ulfsark
- 902
- 1
- 11
- 26
1
vote
1 answer
Why msgpack-c++ do not support vector or vector in my case?
See my code below:(you can compile the code with: g++-4.7 demo.cpp -std=c++11 -lmsgpack)
#include
#include
#include
#include
#include
using namespace std;
template
void pack(T &t, string…

xunzhang
- 2,838
- 6
- 27
- 44
1
vote
2 answers
Convert a string to a decimal base C++
So I'm to take a message (msg) and convert it to all numbers using the decimal base (A=65, B=66 etc.)
So far, I took the message and have it saved as a string, and am trying to convert it to the decimal base by using a string stream. Is this the…

user2059300
- 361
- 1
- 5
- 17
1
vote
2 answers
converting std::string to int using sstream
I'm trying to convert a string of an arbitrary length to an int but so far it works only for strings of limited length. Code so far:
long long convertToInt (std::string x){
long long number;
std::istringstream ss(x);
ss >> number;
return…

maddy
- 57
- 1
- 5
1
vote
1 answer
Won´t read whitespace with ifstream
I am relatively new to C++, so be gentle.
I have a text-file I want to read, but when i read the file it skips the whitespace (space) between separated words.
I tried to take away as much junk-code as possible so it would be easier to read.
#include…

user2292468
- 11
- 2
1
vote
5 answers
sstream not working...(STILL)
I am trying to get a double to be a string through stringstream, but it is not working.
std::string MatlabPlotter::getTimeVector( unsigned int xvector_size, double ts ){
std::string tv;
ostringstream ss;
ss << "0:" << ts << ":" <<…

Kaoru
- 11
- 2
1
vote
6 answers
Tokenize stringstream based on type
I have an input stream containing integers and special meaning characters '#'. It looks as follows:
... 12 18 16 # 22 24 26 15 # 17 # 32 35 33 ...
The tokens are separated by space. There's no pattern for the position of '#'.
I was trying to…

itnovice
- 503
- 1
- 4
- 20