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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:26:50+00:00 2026-06-18T11:26:50+00:00

I have a text file containing names and numbers. The name or the string

  • 0

I have a text file containing names and numbers. The name or the string contains 15 chars and I need to put it to the string. I’m working with structures.

struct grybautojas{
    string vardas;
    int barav, raudon, lep, diena;
}gryb[100];

After that, there are simple calculations which is done right, the problem is, it only reads everything once. After taking a first “box” of information, it just stops. Everything else in the result file is either blank as a string or 0 as an integer.

Here’s my input function:

void ivedimas(){
    char eil[16];
    int b,r,l;

    inFile >> n;
    inFile.ignore();

    for(int i=0;i<n;i++){
        inFile.get(eil,15);
        gryb[i].vardas=eil;
        inFile >> gryb[i].diena;

        gryb[i].barav=0, gryb[i].raudon=0, gryb[i].lep=0;

        for(int m=0;m<gryb[i].diena;m++){
            inFile >> b >> r >> l;
            gryb[i].barav+=b, gryb[i].raudon+=r, gryb[i].lep+=l;
        }

        inFile.ignore();
    }

    inFile.close();
}

And here’s the file containing data:

4
Petras        3
5 13 8
4 0  5 
16 1 0 
Algis         1 
9 6 13 
Jurgis        4 
4 14 2 
4 4  15 
16 15 251 
1  2  3 
Rita          2 
6 65 4 
4 4  13

What’s the problem?

  • 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-18T11:26:51+00:00Added an answer on June 18, 2026 at 11:26 am
        inFile.get(eil,15);
    
        Rita          2 
        Petras        3
        00000000011111
        12345678901234
    

    I don’t count 15, I count 14. Also, some of your lines seem to have a space at the end. You should rewrite your input logic to be much more robust. Read lines and parse them.

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

Sidebar

Related Questions

I have text file, names.txt, with every row containing a last name: Smith Johnson
I have a text file containing string <><> name: idontknow <><><> dob: <> I
I have a text file containing 5 columns of data. The first column contains
In a text file I will have a line containing a series of numbers,
I have a plain text file, containing emails in the following format: Name Surname
I have a text file containing the following information below. I need to loop
I have text file containing a list of 16 bit hex numbers (e.g. '61C7393AA9B3474DB081C7B7CCE1C545')
I have a text file containing strings to encrypt. These strings are indicated by
I have a text file containing the data in following format 12345 Abdt3 hy45d
I have a text file containing unwanted null characters (ASCII NUL, \0 ). When

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.