I want to display data that is in text file and than use it in my c++ code
The problem in my code is it shows empty screen when i try to display it
The format of text file is :
ID : 1
NAME : s
ID :
//and so on
What you had: ifstream fin;//Your provided code will be reading?
If both: fstream fin;//Using both I/O
If you're reading, an approach would be: fin.open("Data1.txt",ios::in);
If you're writing: fin.open("Data1.txt",ios::out|ios::app);
If BOTH: fin.open("Data1.txt",ios::out|ios::app|ios::in);
For writing, use <<
For reading, use >>
Refer to the above link.
Possible reading example:
1 2 3 4 5 6
while (!fin.eof())
{
fin>>id; //I will be on erased the next iteration. Back me up!!!
fin>>name; //I will be on erased the next iteration. Back me up!!!
cout<<ID<<id<<NAME<<name<<endl;
}
Possible writing_to_file example:fin<<id<<'\n'<<name<<'\n';
Edit:
If your data was delimited by newlines, you could use something like this:
hile (!fin.eof())
{
fin>>id; //I will be on erased the next iteration. Back me up!!!
fin>>name; //I will be on erased the next iteration. Back me up!!!
cout<<ID<<id<<NAME<<name<<endl;
}
gives me an error MSB6006"link.exe" exited with code-1073741502
m calling show from another function
After writing it in main it gives me garbage value in output