I have some questions regarding using std::ifstream in C++.
Most are general questions I couldn't find answers to, so might be useful for others, too.
Anyways, I use #include <fstream> and made a variable char line[20].
There is a text file that has several lines of the pattern jxxx (where the xs are numbers), like this:
j1234 j5678 j1111 (and so on)
So, I do this:
#include <iostream>
#include <fstream>
char line[20]
ifstream rfile;
rfile.open("path-to-txt-file");
while (!rfile.eof()) {
rfile.getline(line, 20); (why is 20 needed here?)
cout >> data >> endl;
}
rfile.close();
So the concerns are:
why is the number needed in the
getlinemethod?does
linehave\0at the end automatically? because when we createcharvars likechar text[5]; text = "abc1", it is actually saved as"acd1\0"and what happens to the endlines in the file (\n) after each of thejxxxlines? (I would like to use the lines in more complex code than this, so want to know)Will the program move to the next line automatically? If not, how do I tell it to go to the next line?