I'm trying to get my hands dirty with File IO here. I'm able to do basic stuff but kinda ran out of ideas here.
I want to read input from a text file. Each line of the text file follows this format: <int> <char> <string literal> <float>
, if it doesn't it is to be ignored.
And for each line, we need to store the variables in say four data types:
int i;
char c;
std::string s;
float f;
And print them. For the next line, they are overwritten and printed again.
Here's my attempt:
int main() {
int i;
char c;
std::string s, x;
float f;
ifstream in;
in.open("Input.txt");
if(in) {
std::getline(in,x);
// How do I extract i, c, s and f components from x now?
cout << "\nInteger:" << i << ", Character: " << c << ", String: "
<< s << ", Float: " << f << endl;
}
return 0;
}
PS: Despite efficiency bottlenecks, please use only elementary concepts to solve this issue, not advanced stuff.