Created
          July 19, 2015 13:02 
        
      - 
      
- 
        Save krysseltillada/bc02eae1bb6ca4803753 to your computer and use it in GitHub Desktop. 
    std::ifstreams && std::vector
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #include <iostream> | |
| #include <fstream> | |
| #include <vector> | |
| int main () | |
| { | |
| std::fstream read("sample.txt.txt", std::ifstream::in); | |
| std::string temp_bn, temp_model; | |
| double temp_price = 0.0; | |
| int temp_quantity = 0; | |
| std::vector <std::string> brandname, model; | |
| std::vector <double> price; | |
| std::vector <int> quantity; | |
| if (!read) { | |
| std::cout << "file is not found " << std::endl; | |
| read.setstate(read.badbit); | |
| } | |
| while (read >> temp_bn >> temp_model >> temp_quantity >> temp_price) { | |
| brandname.push_back (temp_bn); | |
| model.push_back (temp_model); | |
| quantity.push_back (temp_quantity); | |
| price.push_back (temp_price); | |
| } | |
| std::cout << "brand name " << std::endl | |
| << "---------- " << std::endl; | |
| for (auto b : brandname) | |
| std::cout << b << std::endl; | |
| std::cout << "model " << std::endl | |
| << "-----" << std::endl; | |
| for (auto m : model) | |
| std::cout << m << std::endl; | |
| std::cout << "quantity " << std::endl | |
| << "-------- " << std::endl; | |
| for (auto q : quantity) | |
| std::cout << q << std::endl; | |
| std::cout << "price " << std::endl | |
| << "-----" << std::endl; | |
| for (auto p : price) | |
| std::cout << p << std::endl; | |
| return 0; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment