how can I serch a word in a txt?
I have a text and it is for example :"hellow hellow hi hi good bye."
and I want to serch the "bye"word what should I do?
You could use a loop to go through each word in the file until you find the correct one.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <fstream>
#include <limits>
int main() {
std::string input;
std::ifstream infile("myfile.txt"); // You may have a different filename, but this is just an example.
while (input != "bye") {
infile >> input;
}
infile.close();
std::cout << input << std::endl; // Just to make sure...
std::cout << "Press the 'Enter' key to close the program.";
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
return 0;
}
This will only work if there are newlines between every word in your file, though. You may have to try a different approach if your file really is laid out like that.