Console prints blank space and is not supposed to do so

So I'm writing a code for my final project and I just encountered a problem

This code snippet prints an extra blank line but that was ok until... I had to store all that data somewhere but it's causing an error

I wanna find out what's the reason behind this

I tried everything from changing the parameters in getline to trying other methods as well but there's always an extra blank line being printed no matter what and using stoi(); causes out of range/overflow errors

Precisely this one

1
2
if (errno == ERANGE || _Ans < INT_MIN != INT_MAX < _Ans)
		_Xout_of_range("stoi argument out of range");


This is the function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void Test() {
	ifstream file;
	string reg,name,gender,clas,age,add,fees,marks;
	int intage,fee,mark;
	file.open("data+updated.csv", ios::app);
	if (!file) {
		cout << "File Doesn't Exist\n";
	}
	while (!file.eof()) {
		getline(file, reg, ',');
		getline(file, name, ',');
		getline(file, gender, ',');
		getline(file, clas, ',');
		getline(file, age, ',');
		getline(file, add, ',');
		getline(file, fees, ',');
		getline(file, marks, '\0');
		cout << reg << "," << name << "," << gender << "," << clas << "," << age << "," << add << "," << fees << "," << marks << endl;
		intage = stoi(age);
		fee = stoi(fees);
		mark = stoi(marks);
	}
	file.close();
} 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void Test() {

    std::ifstream file("data+updated.csv") ;
    if( !file ) std::cout << "File Doesn't Exist\n";

    std::string reg,name,gender,clas,age,add,fees,marks;

    while(
        getline(file, reg, ',') &&
        getline(file, name, ',') &&
        getline(file, gender, ',') &&
        getline(file, clas, ',') &&
        getline(file, age, ',') &&
        getline(file, add, ',') &&
        getline(file, fees, ',') &&
        getline(file, marks, '\0') ) // '\0' is the null character. is this intended?
    {
        // if the attempt to read all these was successful, process the data that was read
        std::cout << reg << "," << name << "," << gender << "," << clas << ","
                  << age << "," << add << "," << fees << "," << marks << '\n' ;
        // etc.
    }
}
Thank you very much @JLBorges solved the issue
Topic archived. No new replies allowed.