Getline help

Hi guys,
I have several function which is not in the int main(). it is however linked by myfile and line. What i am trying to do is retrieve each line from the csv file and calling the other function for each of the line. My problem is that it is only getting the first line. Please help me. Thanks.

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
int main(int argc, char **argv)
{
	std::ifstream myfile2("list.csv");
	std::string name_of_file_to_save;
	while(getline(myfile2,line, '\n')) 
		{
		for(char i=0; i < line.length(); i++)
		{
		if (myfile2.good())
			std::cout << line;
		std::string line2(line);
		std::string st;
			std::remove(line2.begin(), line2.end(), ' ');
			st = line2.substr(0, line2.size()-8);
			std::cout << st;
		name_of_file_to_save = st + ".txt";
		myfile.open(name_of_file_to_save);
		while(myfile.good())
			{
			Data example;
			example.run(argc, argv);
			}	
		myfile.close();
		}
		}
	myfile2.close();
    return 0;
}
If I'm not mistaken you are leaving the '/n' character in the buffer. Use cin.ignore(100,'/n') to clear the new line from the buffer and try that. Read in the line, process it, and then clear the buffer before reading in the next line.
thanks for the suggestion, '\n' in the buffer solved everything.
Topic archived. No new replies allowed.