Hello, I'm trying to write a program that reads lines from a txt file and stores one line into a C-String (array of char) not a C++ String Object, using the ifstream getline() method, then I want to print the contents that are in the C-String. When I try to compile this code as is I get:
"error: no matching function for call to 'getline(std::ifstream&, char[100])'"
I know how to use getline with C++ String objects but for this program I want to use C-Strings, any help or clarification would be appreciated. Thank you.
Why do you need C-Strings? If you have API's that require them, there is always std::string::c_str() (member function) that can be used to convert it...
Apart from that, std::getline() only takes a std::string as input. You probably want to be using something like in.getline(line, 100, '\n') instead. Also, looping on EOF is a bad idea, loop on the actual getline command instead, because EOF is only received when the program has actually tried going past the end of the file.
That is what I was looking for, I want to write this without the use of C++ string objects because I'm going to be tokenizing the C-Strings. I'm not familiar with using getline so I did not know it was possible to replace cin with in when using: cin.getline(char * s, size, delims). But it makes sense with cin being a istream&. Thank you for your time and help!