Questions tagged [sstream]
111 questions
3
votes
2 answers
getline() function in visual studio 2012 working differently, directly skipping to the last line
this is the first time i am using getline() and i think there is something wrong with it!
Here is my code:
ifstream file ("new2.csv");
string val;
while (file.good())
{
getline (file,val);
}
cout<

Prasannjeet Singh
- 756
- 7
- 17
2
votes
1 answer
Convert an ostream into a string (not a sstream)
I specifically need to convert an ostream into a string. To be more precise, I have a function:
ostream& f(ostream& out);
(This function is mainly used for a polymorphic overcharge of the << operator)
In this case, I need to get what is in the…

Simon Löwe
- 21
- 2
2
votes
1 answer
Using same stream object to write to filestream or stringstream
I am trying to use an ostream object to write to either to a filestream of stringstream based user input (similar to fmemopen in Linux).
I realized that ostream doesnt take stringstream or fstream objects but instead takes stringbug or filebuf.
I…

Trancey
- 699
- 1
- 8
- 18
2
votes
1 answer
What is the correct sstream include path for swig interface file?
I am generating a C++ source towards android, with Swig 2.0, and I use . But addind either
%include
or
%include
give me the eror that this include file is not recognized.
What is the correct include then ?
My…

loloof64
- 5,252
- 12
- 41
- 78
2
votes
3 answers
C++ stringstream returning extra character?
I've been attempting to use the C++ stringstream class to do some relatively simple string manipulations, but I'm having a problem with the get() method. For some reason whenever I extract the output character by character it appends a second copy…

Chris
- 600
- 1
- 5
- 11
2
votes
2 answers
Wrong behavior with flag ios_base::app
As far as I know the flag app seeks to the end before each write
const ios_base::openmode std::ios_base::app [static]
Seek to end before each write.
the following program output is: recostream789
std::string str("t2:…

Vinícius
- 15,498
- 3
- 29
- 53
2
votes
1 answer
Simple int to string conversion... Int to const char* invalid
Setting: On Qt Creator, I call this function. I have imported all sstream, string, etc. all of it is in the same class and is defined well in the header file:
std::string int2str(int x) {
std::stringstream ss;
ss << x;
return…

rch
- 229
- 3
- 11
1
vote
1 answer
C++: serialization using sstream
I am testing a serialization code below, which fails for a few numbers. Any idea?
#include
#include
int main()
{
std::stringstream ss;
for (unsigned int m = 0; m < 101; ++m)
{
ss.clear();
unsigned int t…

user180574
- 5,681
- 13
- 53
- 94
1
vote
2 answers
using sstream header file in C++
so I was trying to utilise the istringstream to parse through a text file. The idea is to break down each line by space and based on the substring do stuff. The code works fine except for two things, it double counts last substring for each line and…

noob
- 93
- 1
- 6
1
vote
1 answer
Read text file containing 2D matrix and associated data
I have a text file structured like this:
6
0,2,0,0,5,0
3,0,4,0,0,0
0,0,0,6,1,0
0,0,0,0,2,0
0,0,0,0,2,4
1,0,0,0,0,0
0,5
The first number represents the number of vertices and the 2D matrix is an adjacency matrix. The last line contains start and…

user3308219
- 157
- 2
- 11
1
vote
1 answer
How to use Input String Stream with symbols seperating strings instead of spaces?
note: I just learned about Getline and Streams.
Instead of a space separating first name, last name, and age, how could I separate them with ^ or --?
Is there a function for this? Is this a stupid question, and if so, why?
-The reason for this…

jponce
- 19
- 1
1
vote
1 answer
Converting a single char to std::string prepends \x01
I'm trying to receive values from an unordered map that has std::string as keys, where some of these strings contain only a single character. All my input is coming from a std::stringstream from which I get each value and cast it to a char, and then…

Ted Klein Bergman
- 9,146
- 4
- 29
- 50
1
vote
1 answer
Segmentation fault while declaring an iterator in c++ example of leveldb
I was trying to apply an iteration to my leveldb file, but unfortunately I couldn't get the result. The problem that I'm facing is a segmentation fault in using the pointer of the iterator. I used gdb And I got that the problem is in the line …

MadHer
- 91
- 3
- 11
1
vote
1 answer
Cin skipping input integer
This is a mergesort type program.
If you look at the very bottom of my code in main, when I try and use cin to have the user input an integer variable "select", I think the program might be getting something from the input buffer. I've tried a…

wsamples
- 11
- 2
1
vote
2 answers
How to read integers from console into vector with cin
I'm trying to read integers from the console into my vector of ints. I want to keep reading in integers from a single line until the user clicks enter. I've been trying to use getline and stringstream, but it keeps looking for input after I press…

Grigor
- 11
- 1
- 3