Hi I new here. I am a beginner at programming.
I am having problems updating records in a text file using C++, so I made a test case on the side discovering something weird.
When I access a record and try to print only the first three entries. There are no problems.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
fstream file("t.txt");
int a; string b; int c;
int p = 1;
while(file>>a>>b>>c){
if(a == 1){
cout <<a<<b<<" "<<c;
}
}
return 0;
}
But when I try to print the fourth entry (It was supposed to be in date format but I removed hyphens to see if it solves the problem. It was also originally a string) it does not print anything at all.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
fstream file("t.txt");
int a; string b; int c; int d;
int p = 1;
while(file>>a>>b>>c>>d){
if(a == 1){
cout <<a<<b<<" "<<c<<d;
}
}
return 0;
}
Here is the text file;
0 husnain 20
1 husnain 21 22222222
2 husnain 22
3 husnain 23
4 husnain 24