Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How can I display columns from a text file on new rows in C++

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 538
    Answer it

    I've been trying to display 2 rows with 6 columns, on different rows. I've tried different methods, none of which seems to be working.

    In my .txt I have:
    Corfu [Tab] 5* Gelina Village Waterpark [Tab] 21 May 2017 [Tab] Luton [Tab] 10 nights [Tab] All Inclusive
    Holguin [Tab] 5* Paradisus Rio De Oro [Tab] 22 May 2017 [Tab] Manchester [Tab] 10 nights [Tab] All Inclusive


    What I want the output to be is:
    Corfu
    Accommodation: 5* Gelina Village Waterpark
    Departure Date: 21 May 2017
    Departure Airport: Luton
    Duration: 10 nights
    Board Basis: All Inclusive

    Holguin
    Accommodation: 5* Paradisus Rio De OroStar
    Departure Date: 22 May 2017
    Departure Airport: Manchester
    Duration: 10 nights
    Board Basis: All Inclusive

     

    void Travel::LoadDest()
    {
    
        ifstream file("worlddeals.txt");
        vector<vector<string>>data;
    
        if (file) {
            string line;
            while (getline(file, line)) {
                data.push_back(vector<string>());
    
                stringstream split(line);
                string value;
    
                while (split >> value)
                    data.back().push_back(value);
            }
        }
        for (int i = 0; i < data.size(); i++) {
            for (int j = 0; j < data[i].size(); j++)
                cout << data[i][j] << endl;
    
            cout << '\n';
        }
    }

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: