Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6735975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:04:33+00:00 2026-05-26T11:04:33+00:00

I am trying to read in a file that only have one column, and

  • 0

I am trying to read in a file that only have one column, and write it out to terminal in 3 columns. I have decided to read the one column into separate vector<string>. Then put the vector string into one vector<vector <string> >, before writing out to terminal.

I know it is suppose to be a roster for chores in a flat, hence i know i can split the file by read 15 rows, before i start to read into another vector. However, the number of duties/chores can be changed by the manager, hence i don’t know how many vector<string> i will need, so i can’t just have a set number of vector<strings> pre-declared.

The .dat file is in the form of

Duty1
P1
P1
P1
...

Duty2
P2
P2
P2
...

Duty3
P3
P3
P3
...
*

This is what i want it to look like

Duty1   Duty2   Duty3
P1      P2      P3
P1      P2      P3
P1      P2      P3

This is how it looks like now

Duty1      Duty1     Duty1
    P1        P1        P1
    P1        P1        P1
    P1        P1        P1

I was wondering if anyone could help me spot my mistake

Here’s my code for importing the file.

void DutyManagement::importFlatDuties(){

        ifstream fin1(dutyFile.c_str());

        if( !fin1 ){                                        
            cout << "Unable to find file: " << dutyFile<<endl;
            exit(1);
        }

        else{

            vector <string> temptVec;
            string tempString;

            flatDutyRoster.clear();                                 

            while(true){

                for (int i=0; i<14; i++){
                fin1 >> tempString;                                     

                   if (tempString == "*"){
                    fin1.close();
                    return;
                   }

                   temptVec.push_back(tempString);                          
                  }

                flatDutyRoster.push_back(temptVec);             
             }              
        }           
}

And here is my code for displaying it to terminal

void DutyManagement::displayDuty(){
    importFlatDuties();

    for (int i=0; i<14; i++){
        for (int j=0; j<flatDutyRoster.size(); j++){
            if (i == 0){
                cout<<setw(10)<<"Duty "<<j+1<<": "<<setw(10)<<flatDutyRoster[j].at(i);
            }
            else{
                cout<<setw(23)<<flatDutyRoster[j].at(i);    
            }
        }
        cout<<endl;
    }
}

I’m almost certain it’s just a typo somewhere, but after carefully combing through for several times, i was unable to spot it. It’s my first time trying to work with a vector inside a vector. Perhaps I miss understood something? I don’t know

Any help would be much appreciated. Either you know what’s wrong, or if you’ve a better way of achieving the same result.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:04:33+00:00Added an answer on May 26, 2026 at 11:04 am

    You need to call temptVec.clear() somewhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a really simple XML file that I'm trying to read, but I
I'm trying to read a csv file into R that has date values in
I am trying to read strings from a file that has each string on
I am trying to read in a text input file that contains a list
I am trying to read and sort a csv file that has data that
I am trying to read a file line-by-line, and storing that line of data
I am trying to read a binary file from a program that writes a
I am trying to read database scripts in a Jar file so that I
I have a FileUpload control. I am trying to save the file that is
I have a code as such that reads in an xml file into a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.