+1

Text files in C++

How to search a word from a text file and display the other words aligned to it

c++

3/29/2020 2:44:58 PM

Kool

9 Answers

New Answer

+2

Read the file a line at a time, search the line for the target word, if it's found print the line. You do know this is what the "find" (Windows) and "grep" (Linux) commands can do?

+1

Martin Taylor thanks

+1

You may find answer in http://www.fredosaurus.com/notes-cpp/io/readtextfile.html

+1

You may go through https://www.w3schools.com/cpp/cpp_files.asp

+1

Pl. also see https://www.tutorialspoint.com/cplusplus/cpp_files_streams.htm

0

Martin Taylor what is stream for do i need it? and also getline

0

Use the ifstream class for 8-bit caharacter sets and wifstream for wide character sets. http://www.cplusplus.com/reference/fstream/ifstream/ http://www.cplusplus.com/reference/fstream/wifstream/ for getline see... http://www.cplusplus.com/reference/istream/istream/getline/ http://www.cplusplus.com/reference/fstream/wifstream/

0

narayanaprasad thanks

0

Thanks