# Reading from text file

**URL:** <https://forum.kirupa.com/t/reading-from-text-file/274412>\
**Category:** Uncategorized\
**Created:** [October 29, 2008, 6:23pm UTC](https://forum.kirupa.com/t/reading-from-text-file/274412 "2008-10-29T18:23:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![errcricket](https://avatars.discourse-cdn.com/v4/letter/e/8baadc/32.png) [@errcricket](https://forum.kirupa.com/u/errcricket)\
**Post date:** [October 29, 2008, 6:23pm UTC](https://forum.kirupa.com/t/reading-from-text-file/274412/1 "2008-10-29T18:23:48Z")

</div>

i have a program that reads a text file line by line. it performs some calculations and prints the file out to the screen and newly created text file. it works swimmingly except for one thing: it skips the first line of text. i cheated and entered a blank line for the first line of code and it works…except it now prints the last line twice. any suggestions are greatly appreciated.  
#include\<iostream\>  
#include\<iomanip\>  
#include\<string\>  
#include\<fstream\>

using namespace std;

int main()  
{  
//////////////Input File Check////////////////////////

```
bool flag = false;
fstream bankStatement;
bankStatement.open("bankAccounts.txt");
if(bankStatement.is_open() )
{
    cout &lt;&lt; "Opening customer account information..." &lt;&lt; endl &lt;&lt; endl;
    flag = true;
}

```

```auto
#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>

using namespace std;

int main()
{
//////////////Input File Check////////////////////////

    bool flag = false;
    fstream bankStatement;
    bankStatement.open("bankAccounts.txt");
    if(bankStatement.is_open() )
    {
        cout << "Opening customer account information..." << endl << endl;
        flag = true;
    }

```

.  
.  
.  
string oneLine;  
while (bankStatement)  
{  
string type;  
getline(bankStatement, oneLine);  
bankStatement \>\> accountNumber \>\> accountType \>\> minBalance \>\> accountBalance;

.  
.  
.  
}  
bankStatement.close();  
return 0;  
}

```auto
string oneLine;
    while (bankStatement)
    {
        string type;
        getline(bankStatement, oneLine);
        bankStatement >> accountNumber >> accountType >> minBalance >> accountBalance;

.
.
.
}
bankStatement.close();
return 0;
}

```
