I was working on data structures with C++. Everything looks OK. This is a simple C++ file read. I think this code's output should be:
1
K
3
4
5
But I'm seeing:
1
2
3
4
5
How can I take data[4]
in if
?
This is file.txt
A(1#Jordan)
A(2#Kyrie)
A(3#Lebron)
A(4#Harden)
A(5#Doncic)
This is my code
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
fstream file;
file.open("file.txt", ios::in);
if(file.is_open()){
while(!file.eof())
{
char data[20];
file >> data;
if(2 == data[2])
cout << data[4]<< endl; //**
else
cout << data[2] << endl;
}
}
file.close();
return 0;
}