Quick HELP c++ array and infile
my problem is i cant read the names from a file and into an array
the txt file is formatted like this,,o and i cant use 2d arrays
name place(exp 1st 2nd 3rd) score
exp: blake jacobs 40th 340
bob john 57th 424
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 27 28 29 30 31 32 33
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
#define MAX 100
int main(){
ifstream inFile;
char name[MAX];
char place[MAX];
char score[MAX];
int number;
inFile.open("test.txt");
if (inFile.fail())
{
cout << "No such file"<< endl;
}
int count = 0;
inFile.getline(name,MAX);
inFile.getline(place, MAX);
inFile.getline(score, MAX);
cout << name<<endl;
cout<< place<<endl;
cout << score<<endl;
}
cout << name<<endl;
cout<< place;
|
so how do I print all the names and its just first and last name
and the file has a lot of names
i was told to using getline
Topic archived. No new replies allowed.