I don't see why that shouldn't be working. Here's what I tried:
Code:
#include <iostream>
#include <fstream>
#include <string>
int main() {
std::ifstream stream("stringin.txt");
if(!stream.is_open()) return 1;
std::string first_word;
// reads a word from the stream, just like using std::cin >> first_word.
stream >> first_word;
std::string remainder;
// this reads the remainder of the line.
std::getline(stream, remainder);
std::cout << "First word in the file: \"" << first_word << "\"\n";
std::cout << "Remainder of the line: \"" << remainder << "\"\n";
return 0;
}
This is stringin.txt:
It compiles just fine, and the output is
Code:
First word in the file: "This"
Remainder of the line: " is some data."
(Using stream >> string reads one whitespace-delimited word at a time, whereas getline() reads the whole line, up to and including the newline, though the newline is not stored in the variable you provide.)