I want to use istringstream to print out a large number. Can somebody give me an example of how to use it? I've looked at some examples, but they seem really complicated. Can somebody give me a simple example of how I would go about doing this?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Really complicated? I wonder what kind of examples you've been looking at then :)
Using string streams is just as easy as using other kinds of streams... like cout for example.
Oh and you can't use an istringstream (read "input string stream") for output, obviously. You'll need an ostringstream ("output string stream").
ostringstream out;
out << my_large_number;
Unless you mean large numbers coming from some arbitrary large number library... in that case you'll need to look at the documentation for that library.
Paul
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Why would it? You are using the stream output operator on a STRING stream... the name kind of gives it away, huh? It doesn't print to the screen, it prints to a string.
I want to use istringstream to print out a large number. Can somebody give me an example of how to use it? I've looked at some examples, but they seem really complicated. Can somebody give me a simple example of how I would go about doing this?
Really complicated? I wonder what kind of examples you've been looking at then :)
Using string streams is just as easy as using other kinds of streams... like cout for example.
Oh and you can't use an istringstream (read "input string stream") for output, obviously. You'll need an ostringstream ("output string stream").
ostringstream out;
out << my_large_number;
Unless you mean large numbers coming from some arbitrary large number library... in that case you'll need to look at the documentation for that library.
Paul
Thanks :)
I try to ostringstream a double, but it won't print it out. Here is the piece of my code:
include <sstream>
...
double totalcombos = 1000000000;
..
cout << "Total combinations: ";
ostringstream outstream;
outstream << totalcombos;
cout << "\n";
Why won't it print totalcombos to the screen?
Why would it? You are using the stream output operator on a STRING stream... the name kind of gives it away, huh? It doesn't print to the screen, it prints to a string.
This would fix it:
cout << "Total combinations: ";
ostringstream outstream;
outstream << totalcombos;
cout << outstream.str() << "\n";
And so would this:
cout << "Total combinations: " << totalcombos << "\n";;
Paul
Well, I want to print out the number without it going into scientific notation. I wasn't putting the .str() onto it. Thanks.