[Solved] How do I get a specific string from a text file in C++


Well, what you just need is to iterate the lines of your file and see if the line contains the word you want. If it does, just print the line. Here is the core of what you need:

while (getline (MyReadFile, myText)) {
  if(myText.find(yourString)!=std::string::npos){
           cout<<myText<<\n;
  }
}

The if statement checks if it the string yourString (which is “sea” in your example) is a substring of line. If it is, it will output the line.

2

solved How do I get a specific string from a text file in C++