Computer Science Canada [Tutorial] Extracting data from a string |
Author: | wtd [ Mon Oct 04, 2004 12:07 am ] | ||||||
Post subject: | [Tutorial] Extracting data from a string | ||||||
The standard stream classes we use for dealing with classes have well known capabilities to extract data (integers, floating-point numbers, etc.).
But what if you want to perform a similar operation on a string? The istringstream class allows that very thing.
Additionally, it's possible to check for errors with this class.
|
Author: | Andy [ Mon Oct 04, 2004 4:01 pm ] |
Post subject: | |
very very cool +10 bits |
Author: | Mazer [ Mon Oct 04, 2004 4:31 pm ] |
Post subject: | |
Well... wow. When I was reading this in the morning, I was too tired to know what was going on. But wow, this is quite slick. |
Author: | Andy [ Mon Oct 04, 2004 5:11 pm ] |
Post subject: | |
who needs throw and catch when u have this 8) |
Author: | rizzix [ Wed Oct 20, 2004 1:11 pm ] |
Post subject: | |
yea dodge u need to learn a lot. |
Author: | Andy [ Wed Oct 20, 2004 3:03 pm ] |
Post subject: | |
o psh, u java mod, get out of my c++ world lol |
Author: | wtd [ Wed Oct 20, 2004 4:44 pm ] |
Post subject: | |
Exceptions are still very useful. The method I posted, and the error-checking I demonstrated, is an improvement on the methods one would use to do the same in C (in many many ways). This doesn't mean there's not room for improvement. |
Author: | Andy [ Wed Oct 20, 2004 4:55 pm ] |
Post subject: | |
i noe they are still useful.. im just glad that there is a niceway of doing it without exceptions in c++ |
Author: | wtd [ Wed Oct 20, 2004 5:16 pm ] |
Post subject: | |
Going into pedantic mode for a moment: What I demonstrated was C++ code. C is a different programming language. The two are not interchangeable. |
Author: | Andy [ Thu Oct 21, 2004 3:39 pm ] |
Post subject: | |
you have no proof.. o crap.. it says edited by dodge.. damit |
Author: | wtd [ Thu Oct 21, 2004 5:00 pm ] |
Post subject: | |
I should have quoted you. |
Author: | Andy [ Thu Oct 21, 2004 5:30 pm ] |
Post subject: | |
lol incase you havent noticed, i have c++ powers... and i can edit ur posts lol |
Author: | Geminias [ Fri Jan 13, 2006 5:34 am ] |
Post subject: | |
hey wtd, if you try to input a string manually with: "std::cin >> str;" I found that it doesn't extract. Can you explain why this is? And what might be a suitable alternative to initializing the str at runtime? |
Author: | wtd [ Fri Jan 13, 2006 7:23 am ] |
Post subject: | |
Be aware that if you do that, the string it reads will only be upto the first space, by default. If, for instance, the user types "hello world foo bar", "str" will only contain "hello". You would need to use std::getline to read an entire line of input. |