View Single Post
Old Dec 9th, 2005, 9:48 AM   #3
Klipt
Hobbyist Programmer
 
Join Date: Dec 2005
Posts: 118
Rep Power: 0 Klipt is an unknown quantity at this point
These string streams look quite interesting. Turns out you want an istringstream though, since that acts as a 'input' from a string, i.e. allows you to read from it.

This runs:

#include <string>
#include <sstream>
//#include <ostream>
#include <iostream>

int main()
{
    std::string v("42");
    std::istringstream str(v);
    int x;
    str >> x;   // will get value 42
    
    std::cout << x << std::endl;
    std::cin.sync();
    std::cin.get();
}
Klipt is offline   Reply With Quote