0

I am trying to make a program which puts the contents stored in a stringstream (a large number) into an unsigned long format. But the compiler shows an error

error: invalid user-defined conversion from 'std::stringstream {aka std::basic_stringstream}' to 'long unsigned int' [-fpermissive]|

The code I've written is:

stringstream raw_a;
stringstream raw_b;

//code which reads data into raw_a and raw_b

unsigned long out_a;
unsigned long out_b;

out_a = raw_a;
out_b = raw_b;

I have spent the last hour scouring the web in vain. Any help (including links to any other questions) is highly appreciated.

Vaibhav
  • 13
  • 2

1 Answers1

4

To extract formatted data from a stringstream, do what you'd do with any other stream:

raw_a >> out_a;
Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
  • @Vaibhav: Why do you feel the need to use that word? – Lightness Races in Orbit Mar 11 '15 at 15:32
  • @LightnessRacesinOrbit: Because, in retrospect this was a stupid question. I should have searched for the correct syntax on receiving that error. Unfortunately Stack is the only way I can clarify doubts, as I'm teaching myself. – Vaibhav Mar 11 '15 at 16:09