Mega Code Archive

 
Categories / C++ Tutorial / File Stream
 

Use istrstream to read int, float and char

#include <iostream> #include <strstream> using namespace std; int main() {   char s[] = "10 Hello 0x75 42.73 OK";   istrstream ins(s);   int i;   char str[80];   float f;   // reading: 10 Hello   ins >> i;   ins >> str;   cout << i << " " << str << endl;   // reading 0x75 42.73 OK   ins >> hex >> i;   ins >> f;   ins >> str;   cout << hex << i << " " << f << " " << str;   return 0; } 10 Hello 75 42.73 OK"