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 8194551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:51:51+00:00 2026-06-07T04:51:51+00:00

If I open a new file for input, and I call input >> listSize;

  • 0

If I open a new file for input, and I call input >> listSize; outside of a while loop and then continue calling input >> anothervariable will it automatically progress through the file or will it read the first line again?

Example:

input >> listSize;
BaseStudent* studentlist = new BaseStudent[listSize.atoi()];
while (!input.eof())
{
         input >> anothervariable; // I want this to start on the second line, not the first

}

The input file looks like this and we can code to the pattern (ignore the extra blank lines):

12

Bunny, Bugs

Math 90 86 80 95 100 99 96 93

Schmuckatelli, Joe

History 88 75 90

Dipwart, Marvin

English 95 76 72 88

Crack Corn, Jimmy

Math 44 58 23 76 50 59 77 68

Kirk, James T. 

English 40 100 68 88

Lewinsky, Monica

History 60 72 78

Nixon, Richard

English 35 99 70 70

Lincoln, Abraham

History 59 71 75

Clinton, William

Math 43 55 25 76 50 58 65

Duck, Donald

English 34 100 65 65

Duck, Daffy

History 55 70 70

Bush, George

Math 44 54 29 75 50 55 60
  • 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-06-07T04:51:53+00:00Added an answer on June 7, 2026 at 4:51 am

    Others have already pointed out that the answer to your question is “yes”, so I won’t worry about that part.

    As for the rest, I think I’d write it a bit differently. Your file obviously represents structured data, and I’d write the code to reflect that fact reasonably directly. I’d start by defining a structure reflecting the data in the file:

    struct test_scores {   // maybe not tests. Change if appropriate
        std::string student;
        std::string course;
        std::vector<int>
    };
    

    Then, I’d write a function to read one of those items from the file:

    std::istream &operator>>(std::istream &is, test_scores &ts) { 
        // for the moment assuming there are no blank lines in the file.
        std::getline(is, ts.student);
        std::string temp;
        std::istringstream buffer(temp);
        buffer >> ts.course;
        int score;
        while (buffer>>score)
            ts.scores.push_back(score);
        return is;
    }
    

    In C++, however, it’s really easier to just read whatever amount of data is there, than to prefix the data with the count. Given that count is present, the easiest thing to do is probably to just read and ignore it:

    std::string ignore;
    std::getline(infile, ignore);
    

    Then we can read the real data pretty easily:

    std::vector<test_scores> student_scores;
    test_scores tmp;
    
    while (infile >> tmp)
        student_scores.push_back(tmp);
    

    …or, we can use C++’s handy-dandy istream_iterators to simplify the code even more:

    std::vector<test_scores> student_scores((std::istream_iterator<test_scores>(infile)),
                                             std::istream_iterator<test_scores>());
    

    That’s it — it defines the vector and initializes it from the input file, all in one (fairly) simple operation.

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

Sidebar

Related Questions

When I use FuzzyFinder plugin to open a new file in MacVim, it opens
Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here
I have the following code: using (BinaryReader br = new BinaryReader( File.Open(FILE_PATH, FileMode.Open, FileAccess.ReadWrite)))
When using NERD Tree on MacVim, I can open a file in a new
text_file = open("new.txt", "r") lines = text_file.readlines() for line in lines: var1, var2 =
I am using iframe to open new .aspx page from parent page. child page
I have some problem with my open new window popup which it can read
I'm new to VSDO, and i want to open new template/word popup window within
I have a windows form where in I open new threads for server communication.
I have window form in my WPF Application when I open new window from

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.