Advertisement
Guest User

Untitled

a guest
May 28th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5.  
  6.  
  7. int
  8. main(void){
  9.     int from, to, hmuch;
  10.     std::string buf;
  11.    
  12.     std::ifstream rFile("data.txt", std::ifstream::in );
  13.    
  14.     while( std::getline(rFile, buf)){
  15.    
  16.     /*сплит строки*/
  17.    
  18.         std::string delim = ":";
  19.         std::string token;
  20.         size_t pos = 0;
  21.    
  22.         pos = buf.find(delim);
  23.         token = buf.substr(0, pos);
  24.         from = atoi(token.c_str());
  25.         buf.erase(0, pos + delim.length());
  26.  
  27.         pos = buf.find(delim);
  28.         token = buf.substr(0, pos);
  29.         to = atoi(token.c_str());
  30.         buf.erase(0, pos + delim.length());
  31.  
  32.         pos = buf.find(delim);
  33.         token = buf.substr(0, pos);
  34.         hmuch = atoi(token.c_str());
  35.         buf.erase(0, pos + delim.length());
  36.  
  37.         std::cout << from << std::endl;
  38.         std::cout << to << std::endl;
  39.         std::cout << hmuch << std::endl;
  40.         std::cout << "***\n";
  41.     }
  42.    
  43.     rFile.close();
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement