Why can't I just use getline(infile,name) without a delimiter?
If you do, then a default delimiter is used.
has the same effect as getline(infile,name, '\n');
So really, you cannot avoid using a delimiter. The whole intention behind getline() is that it continues reading characters into the string until it finds a delimiter (or reaches the end of the stream).
The point is, in the context of the data in your file, both the tab '\t' and newline'\n' characters are present. You choose which one to use depending on what you are trying to achieve.
Before I start bugging you guys :D just one tiny concern please :) suppose on text file, this is the name on line 1 with scores. I use this function getline(infile, name,"\n") the "n" means newline. The string reads all the data in that line until new line is found. So, should it not read fahman David khan? Because new line is not happening at that time.
1 2 3
Fahman David khan 95 34 64
Won't bug you Fter this but I do appreciate for the help :D
Before I start bugging you guys :D just one tiny concern please :) suppose on text file, this is the name on line 1 with scores. I use this function getline(infile, name,"\n") the "n" means newline.
std::getline takes a char argument as the delimiter, not a pointer to char (std::getline(infile, name, '\n'))
If the format of the file is as you indicate in the post above, getline will return an empty string, because the first line consists of only a newline. Assuming you do another getline the string extracted would be "Fahman David khan 95 34 64"
It should be noted that if you are using the extraction operator (>>) to read the numbers from the file, those operations will leave any trailing whitespace in the input buffer (including newlines) which will be encountered by a subsequent getline with the default '\n' delimiter which will, therefore, only extract an empty string. One can avoid that by using infile >> std::ws prior to using getline.