Basic code I just moved to a clean compllier to run and fix what i needed to fix.
I am haveing problems with reading from a file and storing the infomation to a struct.
I get the program to read and print out on the screen ( that is how i test to make sure it opens).
I also have some code after the file to make sure that it prints out after the file. the code between that and the inData.seekg(0); is my problem. I have posted my recent one.
this is no error message, but when i compile it it just ends at the end of the file and does not print out the bottom message.
cout << endl; //adds some space between the echo text
cout << endl; //file and the averages.
// Must clear the end-of-file flag to be able to rewind and re-read from the beginning.
inData.clear();
// 'Rewind' the input stream to the beginning - i.e. byte 0
inData.seekg(0);
no error when i check, but when i compile it is stuck on an infitle loop with hello.
while(inData)
{
cout << "hello" << endl;
for(counter =0; counter < 100; counter++)
{
inData >> customer.name
>> customer.amount;
// >> customer.registered;
total_customer++;
}
// Must clear the end-of-file flag to be able to rewind and re-read from the beginning.
inData.clear();
// 'Rewind' the input stream to the beginning - i.e. byte 0
inData.seekg(0);
}
inData.close(); //closes the file
//needs to be able to close
//dose not right now
}
tried this one does the same thing
no error when i check, but when i compile it is stuck on an infitle loop with hello.
while(!inData.eof())
{
cout << "hello" << endl;
for(counter =0; counter < 100; counter++)
{
inData >> customer.name
>> customer.amount;
// >> customer.registered;
total_customer++;
}
// Must clear the end-of-file flag to be able to rewind and re-read from the beginning.
inData.clear();
// 'Rewind' the input stream to the beginning - i.e. byte 0
inData.seekg(0);
}
so i am guessing that it is the second while(!inData.eof()) that is wrong.
Reading it and saving it to the struct at the same time should work right? researching it now.
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Basic 3 stuff.
Dev-C++ 4.9.9.2, Windowz XP Pro
Basic code I just moved to a clean compllier to run and fix what i needed to fix.
I am haveing problems with reading from a file and storing the infomation to a struct.
I get the program to read and print out on the screen ( that is how i test to make sure it opens).
I also have some code after the file to make sure that it prints out after the file. the code between that and the inData.seekg(0); is my problem. I have posted my recent one.
this is no error message, but when i compile it it just ends at the end of the file and does not print out the bottom message.
trying to print info from the struct.
thanks for helping, i think i got everthing.
Akumanight
cout << "total customers: " << total_customer << endl;
include <iostream>
include <fstream>
include <string>
include <iomanip>
using namespace std;
enum account_type
{
unknown, Checking, Savings, Credit_Card
}; //customers account type
account_type registered;
struct Bank_Customer_Record
{
char name[100];
float amount;
account_type account;
};
void database();
int main()
{
database();
system("PAUSE"); //needed in bloodshed to pause program
return EXIT_SUCCESS;
}
//reads the database of names and stores them in a struct
void database()
{
cout << fixed << showpoint << setprecision(2);
}
Basic code I just moved to a clean compllier to run and fix what i needed to fix.
alright i tried
compiles but now is stuck on an infinet loop with the first name in the text file.
while(!inData.eof())
{
getline(inData, line);
cout << line << endl;
for(counter =0; counter < 100; counter++)
{
inData >> customer.name
>> customer.amount;
// >> customer.registered;
total_customer++;
}
cout << endl; //adds some space between the echo text
cout << endl; //file and the averages.
// Must clear the end-of-file flag to be able to rewind and re-read from the beginning.
inData.clear();
// 'Rewind' the input stream to the beginning - i.e. byte 0
inData.seekg(0);
thanks
the bank.txt file is just a basic file like this
Name
amount
type
Ron Harold
1467.45
Checking
Tiffany Mace
345.23
Credit Card
Thanks
i have tried
no error when i check, but when i compile it is stuck on an infitle loop with hello.
while(inData)
{
cout << "hello" << endl;
for(counter =0; counter < 100; counter++)
{
inData >> customer.name
>> customer.amount;
// >> customer.registered;
total_customer++;
}
// Must clear the end-of-file flag to be able to rewind and re-read from the beginning.
inData.clear();
// 'Rewind' the input stream to the beginning - i.e. byte 0
inData.seekg(0);
}
inData.close(); //closes the file
//needs to be able to close
//dose not right now
}
tried this one does the same thing
no error when i check, but when i compile it is stuck on an infitle loop with hello.
while(!inData.eof())
{
cout << "hello" << endl;
for(counter =0; counter < 100; counter++)
{
inData >> customer.name
>> customer.amount;
// >> customer.registered;
total_customer++;
}
// Must clear the end-of-file flag to be able to rewind and re-read from the beginning.
inData.clear();
// 'Rewind' the input stream to the beginning - i.e. byte 0
inData.seekg(0);
}
so i am guessing that it is the second while(!inData.eof()) that is wrong.
Reading it and saving it to the struct at the same time should work right? researching it now.
Thanks