.dat file!
Hi! I know I had this question before but somehow my program doesn't work! I have this .dat file called VotersRoll.dat with the following data:
19810102009 1 0
19792003008 2 0
19851010890 3 1
19900909897 2 0
19561812567 6 0
19682703345 7 1 |
All I want is to get the data separately like for output:
Voter's ID: 19810102009
Column 1: 1
Column 2: 0 |
etc.
I have to ask the user for his/her ID and then need to check if it's in the list of the .dat file.
This is all I have so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream in_stream("VotersRoll.dat");
if (!in_stream)
{
cout << "Could not open file" << endl;
return 1;
}
int fileID, fileF1, fileF2;
in_stream >> fileID >> fileF1 >> fileF2;
cout << "Voter's ID: " << fileID << endl;
cout << "Column 1: " << fileF1 << endl;
cout << "Column 2: " << fileF2 << endl;
in_stream.close();
return 0;
}
|
It runs but it gives me this output...
Voter's ID: 4273494
Column 1: 2293592
Column 2: 4273392 |
Please help!
What about the getline(); function?
Aceix.
Your ID may be to big to be hold in an int
use `std::string' instead
@ne555 is right, but I wouldn't use a string I'd probably use uint32_t or uint64_t
I am very new with this, I don't know what
is...
And if I use a std::string, where does it go in the program?
:)
Google them then.
Last edited on
Topic archived. No new replies allowed.