I am loading my file data to 2d dynamic string array, but the problem is whenever space is encountered column is incremented. For example
Expected output:
Name - Omer saleem
Registration - cs151054
Address - xyz university
cell -302103103210
output that I am getting:
Name - Omer
Registration -saleem
Address - cs151054
cell - xyz
mycode:
string reading;
getline(read, reading, (char)read.eof());
while (!read.eof()){
getline(read,reading);
}
for (int i=0;i<reading.length();i++){
if (reading[i]=='\n'){
rows++;
}
}
ifstream read ("students.txt");
students = new string *[rows];
for (int i=0;i<rows;i++){
students[i] = new string [COLS];
}
for (int i=0;i<rows;i++){
for (int j=0;j<COLS;j++){
read >> students[i][j];
}
}
}
}
do you have an email so I can send the complete program?
There are multiple files, the input file looks like
omer saleem(\t)cs151054(\t)dsu(\t)003023230232
(where \t is tab)
I don't want to post me email address here. All bots would see it and I get enough spam already.
If you enable PMs on your account I send it per PM to you.
Anyway reading this file is not so difficult. The only problem is that the name contains a space so to read the name you will need to use getline(read, reading, '\t'), for the rest of the line you can just use cin >> someString;