Questions tagged [stringstream]

stringstream provides an interface to manipulate strings as if they were input/output streams.

The objects of this class maintain internally a pointer to a stringbuf object that can be obtained/modified by calling member rdbuf. This streambuf-derived object controls a sequence of characters (string) that can be obtained/modified by calling member str.

1178 questions
-1
votes
2 answers

How to convert strings to doubles in C++ using stringstream

I'm trying to take strings from vectors and convert them into doubles using stringstream. However, when I run this code: double tempDob; stringstream ss; ss << tempVec[3]; ss >> tempDob; I get weird stuff instead of a normal double. Here's…
-1
votes
1 answer

Unexpected results when using std::stringstream

I am a beginner in C++, started last week. I am trying to make a simple program converting a number of inches to foot inch notation: E.g. 62 turns into 5'2". However when I try to compile I have some error in line 8. I don't know what it is. Thanks…
mtheorylord
  • 115
  • 9
-1
votes
1 answer

using ifstream from a stringstream converted in a string

I really don't understand why if I use f.open(filename.c_str(),ios::in) works only if filename is a string defined as a string type, but not if filename is been converted from a stringstream type. I need stringstream type, because I have to open…
ADHAFERA
  • 69
  • 1
  • 5
-1
votes
1 answer

Stringstream trouble

so,i'm trying to do a conversion(integer to string) and then add this string with another.But it seems stringstream is not working..(it's normally working but the loop causes troubles) I'm done with google & almost tried everything but can't get…
inhaler
  • 175
  • 1
  • 2
  • 12
-1
votes
1 answer

using stringstream and getline to read the first two numbers of each line

What I need to do: I have a vector of lines right now, v[0] is the first line and so on. I would like to read the first number from each line as the challenge and the second number from each line as the judge and then apply the conditions in the…
-1
votes
1 answer

How to access other comma separated values from a txt file. C++

ifstream f("events.txt"); if (f.is_open()) { string l,t; string myArray[5]; int i = 0; while (getline(f, l)) { getline(stringstream(l), t, ','); cout << t << endl; myArray[i] = t; cout <<…
Zone
  • 5
  • 2
-1
votes
2 answers

Code reading extra line in my loop?

My goal is to read from an input file and count the number of lines that have at least 1 lowercase letter and 1 digit. I have already solved the rest of my code which counted all of the lowercase, uppercase, digits, characters and words no problem.…
ryanpback
  • 275
  • 4
  • 17
-1
votes
1 answer

`std::stringstream::operator>>()` cannot decude the template type

I'm trying to write a generic string parser function by using std::ostringstream class. #include #include #include template ValueType parse_string(const std::basic_string &…
hkBattousai
  • 10,583
  • 18
  • 76
  • 124
-1
votes
1 answer

C++ converting from string array to int array without crashing the program

I'm trying to find the simplest way to convert a string array of numbers to an int array so that I can use it in calculations. Stringstream and stoi have so far both crashed the program or not worked. Any help? Thanks! int counter = 0; string…
John M.
  • 1
  • 1
-1
votes
1 answer

String Stream is adding a new line when converting an int

I am trying to limit the length of a line to fit on a page nicely and am using the following code if (!primes[j]) { stringstream st; st << j; test += " "+st.str(); if (test.length() > 71) { cout << line << endl; line…
Fireynis
  • 407
  • 6
  • 13
-1
votes
2 answers

Passing a object member to a template function expecting an integer

I have been reading and reading posts asking similar questions but my doubts persists. So I have a class like this: class Instruction{ public: unsigned int getAddress(); uint32_t getValue(); private: unsigned int address; uint32_t…
joaomlap
  • 195
  • 3
  • 13
-1
votes
1 answer

C++, Trouble with string and int conversion

I know how to convert the string when it's just made up of integers, or it begins with ints. I am trying to convert to an integer when the string starts with a char in the beginning, or middle. I've tried running through a for loop, checking if…
-1
votes
2 answers

C++ Error using a custom ifstream class with a variable as argument

I am using a custom ifstream class class plb_ifstream : public Parallel_istream { public: plb_ifstream(); explicit plb_ifstream(const char* filename, std::istream::openmode mode = std::ostream::in ); ~plb_ifstream(); virtual…
Fowaz Ikram
  • 133
  • 6
-1
votes
1 answer

Using fstreams and stringstreams: Trouble getting a char after getting the string (C++)

(C++) I want to display the first part, which works fine, then the dollar sign on another line, then the price. Here's what I have: string mystring; ofstream oFile( "C:\\beer.txt" ); oFile << "Heineken#$7.99" << endl; fstream File( "C:\\beer.txt" ,…
JCoder
  • 189
  • 1
  • 3
  • 17
-1
votes
4 answers

recursive call should output reverse string

Hello together void rev_out(istream& is){ char a; is >> a; if(a!='g')rev_out(is); cout << a; } int main() { stringstream is("abcdefg"); rev_out(is); return 0; } now the Output is gfedcba, but i have a problem. I`d like to give an universally…
Suslik
  • 929
  • 8
  • 28