Enter from keyboard a letter. Read text from given text file and print into another text file all words starting with entered letter and row number where word was found in given file.
#include <bits/stdc++.h> using namespace std; // driver code int main() { fstream file; // Input stream class to // operate on files. ifstream ifile("file.txt", ios::in); // Output stream class to // operate on files. ofstream ofile("file2.txt", ios::out | ios::app); // check if file exists if (!ifile.is_open()) { // file not found (i.e, not opened). // Print an error message. cout << "file not found"; } else { // then add more lines to // the file if need be ofile << ifile.rdbuf(); } string word; // opening file file.open("file2.txt"); // extracting words form the file while (file >> word) { // displaying content of // destination file cout << word << " "; } return 0; }
while
cin
word
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)