I would like to obtain the first character from a text string and assign it to a variable. I tried to create an ifstream object to open a text file and using its get() function but was unsuccessful.
I would like to obtain the first character from a text string and assign it to a variable. I tried to create an ifstream object to open a text file and using its get() function but was unsuccessful.
Show the code where you tried to open and read from the file.
Jim
Code:char letter ifstream reader("poem.txt"); if (!reader) { cout << "Error opening input file" << endl; return -1; } else reader.get(letter); cout << letter; reader.close();
Other than missing a semicolon, a main function and include files your snippet looks correct.
Jim