I seem to have a fundamental misunderstanding on file input. I assumed my method would work for a project I am working on, but it simply does not. Here is the code:
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main(){
ifstream input;
char fname[20], lname[20];
input.open("text.txt");
input.getline(lname, 20, ',');
input.getline(fname, 20, ' ');
cout << lname;
cout << fname;
}
From a file I have:
Squarepants, Spongebob
and the cout statements do not output anything
What I am doing wrong?
thanks
input.ignore()after the first getlineinput.ignore(), or get rid of the third argument in the second call togetline.