string - Trouble understanding istringstream in C++ -


i new c++ , wondering how can understand functions , classes do. example told use "istringstream" homework assignment. have looked online , found site cplusplus.com lot of references. problem have understanding reference page.

on "istringstream" reference page given following code:

// istringstream constructors. #include <iostream>     // std::cout #include <sstream>      // std::istringstream #include <string>       // std::string  int main () {    std::string stringvalues = "125 320 512 750 333";   std::istringstream iss (stringvalues);    (int n=0; n<5; n++)   {     int val;     iss >> val;     std::cout << val*2 << '\n';   }    return 0; } 

in code above, need assignment not understand why works. created istringstream object called iss, later used "iss >> val". part confused with. do?

i have tried reading text above explains each function in class did not understand of it. example, 1 of first lines on reference page says

default (1)   explicit istringstream (ios_base::openmode = ios_base::in); 

how interpret line? can see function takes 1 argument "ios_base::openmode = ios_base::in".

i believe this page you're looking for. defines mysterious >> operator. overloaded several different ways, means it's working scanf function several different data types.

your compiler looks @ iss >> val , says "hmm...iss istringstream , val int. aha! looks istringstream has operator>> takes int&, i'll use that!"

edit: istream has operator>> int&. istringstream inherits those.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -