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

  • Home
  • SEARCH
  • 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 6826461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:09:01+00:00 2026-05-26T22:09:01+00:00

I have a file with random data for accounts. The data in the file:

  • 0

I have a file with random data for accounts.
The data in the file:

5

2871 2.19 8

1234 95.04 23

3341 0.00 10

3221 -1.08 21

7462 404.14 4

3425 4784.00 200

3701 99.50

JUNK SHOULD NEVER GET HERE

3333

The first number 5 will always be the number of accounts that need to be processed.
I want to be able to read that number and set it as the number of accounts.

So my question is how can I read the file and read line by line and set the first number to the number of accounts that need to be processed.

Code so far:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main() 
{

    double NumberOfAccounts;

    ifstream File("test.dat");
    string line;

    if(File)
    {
        while(getline(File,line))
        {
            NumberOfAccounts=line[0];
        }

    File.close();
    }

    cout<<NumberOfAccounts;

    system("pause");

    return 0;
}

Right now it just prints out 51.

Any tips/help would be appreciated.

  • 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-26T22:09:01+00:00Added an answer on May 26, 2026 at 10:09 pm

    NumberOfAccpounts is double, you are assigning the first character of line…
    I assume you menat the first line in the file.

    My C++ is crap so

    pseudocode

    if(File)
    {
      if getLine(File, line)
      {
        NumberOfAccounts =atof(line);
      }
      File.close();
    }
    cout<<NumberOfAccounts;
    system("pause");
    return 0;
    

    atof is one way to convert a string to a double. You don’t need to read the entire file to get the first line.

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

Sidebar

Related Questions

I have a txt file and each line has a set of random strings,
I have a text file that looks a bit like: random text random text,
okay, so i have a text file with example content below line1with some random
If I have a a textfile say file.txt and it contains random words like:
I have a file in which I read in data. Suppose the file has
I have web.config file from some application. It is located in some random location.
I have following data in text file 375020222511963 284970411563422 290245594366931 I need to retrieve
Say I have a program that creates a database file, and imports data to
I have an file with a specific data I would like to pull. The
I have text file as follows: HEADER INFO Last1, First1 Movie1 (1991) random stuff

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.