Read from a file

I have saved
1 subo 34 54 65
2 suvi 43 90 54
3 nana 45 87 98
4 Anshu 77 88 55
5 SUBA 90 23 34

I want to print above data but it outputs infinite lines of "1s011"
can anyone show me the erorr..?
thanks..

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
int id;
int m1,m2,m3;
char st;
int nu;

ifstream show("class.txt");


show>>id>>st>>m1>>m2>>m3;
while(!show.eof())
{
cout<<id<<st<<m1<<m2<<m2<<endl;
show>>id>>st>>m1>>m2>>m3;

}


show.close();

return 0;
}
Last edited on
A char is a single character.

A string is a string of characters.

1
2
3
4
5
6
7
8
9
10
#include<iostream>
#include<fstream>
#include <string>  // <- add this

using namespace std;
int main()
{
    int id;
    int m1,m2,m3;
    string st;  //<- change this from a char to a string 
Thanks..!
Topic archived. No new replies allowed.