Robert E Robert E - 7 months ago 36
C++ Question

How to get a certain word in string of getline?

How can someone get only a certain word in a string of a getline method? For example:


hi guys
im @@Paul \t\t [GET THIS]

string line;
string word;
ifstream file ("test.txt");

if (file.is_open()) {
while (getline(file, line)) {
if (line.find("@@Paul") != string::npos) {
strcpy(word, line.c_str());

How can I code it so when I find
it only takes the characters (
) after the double tab (


this is definition of getline function: istream& getline (istream& is, string& str, char delim);

Delim is a delimitier which stops getline from reading the stream after to the given character. so you can do something like this:

string trash;
string properline;

getline(file, trash, '\t');
getline(file, trash, '\t'); //second tab, still trash
getline(file, properline);