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
3 answers

Cannont convert char to int?

I'm unable to convert a char to an int and I have no idea why. I simply want to convert some data that I parse from a CSV from string to int and the compiler won't let me. I get this error: invalid cast from type…
Trisitian
  • 71
  • 1
  • 1
  • 6
-1
votes
2 answers

If the first element contains any zero, than my program is behaving in an undesired way

What is wrong with this. Everything is working except the first element if the first element contains any zero. e.g. input -> 100 output -> 10 input->6030 output->630. Question: Input Format The first and only line consists of n integers separated…
HarshM
  • 21
  • 6
-1
votes
3 answers

How to take a function using stringstream to parse the numbers, and put them into an array?

So I am using stringstream in a function in c++ to take the numbers from a string, and then return the numbers to an array in main, but for some reason, they always return as 0 instead of the actual numbers. Code is below, does anyone know how to…
-1
votes
1 answer

Why is stringstream only reading the first digit in my integer? How do I make it so it only moves on at a blank space?

Relevant code is as follows: string output; char letter, number, symbol; cout << "Input a letter, number, and a symbol separated by a space: "; getline(cin, output); istringstream(output) >> letter >> number >> symbol; However, if I type in a…
-1
votes
1 answer

If an integer is entered into the StringStream, double it and print it

I need to be able to enter a sentence and have it spit back out. However, if a number is entered in the sentence, it should be output along with the words but it must be doubled. I've tried implementing an if statement into my code to see if I…
-1
votes
1 answer

How to use stringstream to append in a loop? For example

I'm trying to use ostringstream to concatenate a string in a loop. Unfortunately, only the most recent stream is used. Can anyone point me in the right direction on accomplishing this or similar (other the + with string…
user9405153
-1
votes
1 answer

Take +/- ints from string in c++

I've been beating my head against the wall for this one for awhile now. What I am trying to do is read a line of input and take the ints from it and store that for later use. Example inputs: subi r23, R10, 435 Lb r3, -3(r10) Example…
Ker
  • 1
  • 2
-1
votes
3 answers

C++ Convert a vector which has a address held as a string, into a new Vector

Can I get some advise? Instead of returning the vector from the function as a pointer or a reference, I am returning it as a string which contains the address. (I had good reason for this). ^That part was successful, the part I can't seem to figure…
Josh
  • 1
  • 2
-1
votes
3 answers

Read a file line-by-line twice using stringstream

I Need to read a file line-by-line twice. The file content is expected to fit into memory. So, I would normally read the whole file into a buffer and work with that buffer afterwards. However, since I would like to use std::getline, I need to work…
0xbadf00d
  • 17,405
  • 15
  • 67
  • 107
-1
votes
1 answer

I want to make string which is influenced by variables changing (c++)

I'm using stringstream in put variables in string like int c; stringstream ss; string st; ss << "some texts" << c; st=ss.str(); cout << st; but when i change the c and call back ss.str() again, ss.str() is saving ex-int c, not new one. Is there…
-1
votes
1 answer

Assigning variables from configuration file to int16_t variables in c++

I have use stringstream to parse the configuration file. The c++ integer variables are working fine while assigning the values from the text file.However, when I assign the read value from configuration file to c++ int16_t variables, it just assigns…
nzy
  • 854
  • 2
  • 15
  • 28
-1
votes
1 answer

std::stringstream output does not work the same as std::string

i am currently working on a program whereby i can substitute alphabets in a text file(called plaintext.txt), along with a keyfile, and create a ciphertext when i run a command to mix them together. The working code is as shown below: string…
fabian
  • 5
  • 2
-1
votes
2 answers

Segmentation fault when inserting into the stringstream

I get a segmentation fault, but I don't use any pointers. It's being happened when I insert into the stringstream. std::string Relations::toString() { std::stringstream restring; restring << ID << "("; restring << reList[0]; //…
JKdub
  • 9
  • 2
-1
votes
2 answers

C++ getline results in segmentation fault when the end of the string is reached

I have this simple code splitting a string made of equalities separated by ampersands: std::string cmd = "par1=1&par2=ciao&par3=1.2e4" std::stringstream ss(cmd); std::string argdef; std::vector pairs(0); while (std::getline(ss,…
Hybridslinky
  • 131
  • 1
  • 13
-1
votes
2 answers

How to convert string to char* using stringstream?

I have a function like this: template void parse_to_T(const std::string& str, T* result) { std::stringstream ss; ss << str; ss >> *result; } this function is mean to convert the string to the specified type. it is work to…
李浩然
  • 243
  • 1
  • 3
  • 9