Matching program that takes input from a text file

Assignment Help C/C++ Programming
Reference no: EM13168165

need to make a string matching program that takes input from a text file and outputs that match (if there is one) asked from the user. i have done this part , the only problem is that , with the output match , i also need to print some words before and after the actual match , like you would search in google and it gives you the results , with extra details ....  how could i do that sort of searching?

here is my program ..

 

#include <iostream>

#include <string>

#include <fstream>

 

using namespace std;

 

int main()

{

    ifstream myfile ("text.txt");

    string line;

    int offset;

    string tosearch;

 

    cout<< "Enter the word to be searched from the text file" << endl;

    cin>> tosearch;

 

        while (!myfile.eof())

        {

            getline(myfile,line);

            if (offset = line.find(tosearch, 0) != string::npos)

            {

                cout << "The word has been found"<< endl;

 

            }

        }

 

    cin.get();

    return 0;

 

}

 

 

Reference no: EM13168165

Questions Cloud

Program that will calculate the heat transfer of a substance : write a program that will calculate the heat transfer of a substance (water) given three different shapes. The user has to be able to input the type of shape, so that the computer can calculate area, and plug it back in to the equation for heat trans..
Using your musicalinstrument class : Finally, create a Java test class that simulates using your MusicalInstrument class.  In your test class you should at a minimum: a) Construct 4 instances of your instrument, b) tune your instruments, c) print the name of your instrument d) print ..
Dubbing was coined as a term of copying : Dubbing was coined as a term of copying media in the 1980's for all mediums. What term was a major issue during the process of continously dubbing media? Digitization cured this issue.
Write a java program that uses the elapsed time : Write a Java program that uses the elapsed time for an event in second and then outputs the elapsed time in hours, minutes and seconds. (For example, if the desired time is 9630 seconds, then the output is 2: 40: 30)
Matching program that takes input from a text file : need to make a string matching program that takes input from a text file and outputs that match (if there is one) asked from the user. i have done this part , the only problem is that , with the output match , i also need to print some words before a..
Called cbankaccount : Create a base class, called CBankAccount, and two additional classes (each derived from CBankAccount), called CSavingsAccount and CCheckingAccount.
Collection of scores (type int) for the last exam i : After being given a collection of scores (type int) for the last exam in your computer course, you are to computer the average of the scores and assign grades (O, S, U i.e. Outstanding, Satisfactory, Unsatisfactory)) to each student according to the ..
Prompt the user for 3 sentences of text : Prompt the user for 3 sentences of text. Pass these pieces of text into a function connect() which will connect all three sentences into one long sentence. Pass the combination sentence back to the main program, where it is printed.
Generate a set of 75 random integers in the range -26 to + 4 : Write a program that will generate a set of 75 random integers in the range -26 to + 42. The program

Reviews

Write a Review

C/C++ Programming Questions & Answers

  While loop that allows the user to continue entering

This code should include a while loop that allows the user to continue entering employees as long as they want to continue:int main(){Real payrate,hours, gross,again;

  Program to add numbers and display sum

For each of problems write C++ code to do the required task. Receive the number and find out whether it is odd or even.

  Use functional decomposition to solve

Use functional decomposition to solve this problem, and code the solution using functions wherever it makes sense to do so. Your program should check for invalid data such as nonpositive dimensions, number of rooms less than 1.

  Write a program that will be used to gather statistical data

Write a program that will be used to gather statistical data about the number of movies

  Design and implement a library system

Design and implement a library system that does the following: ? Takes details of a student/library users: first name, last name, other names, user ID number, and nationality.

  Write a program to calculate a person''s net pay

Write a program to calculate a person's net pay after subtracting federal income tax.The program should ask the user to enter the person's name, social security number, gross pay, and the number of dependents.

  The knight''s tour problem

The knight's tour problem is as follows: given an initial position for a single knight on an otherwise empty chessboard, find a sequence of 64 moves that will make the knight visit every square on the board exactly once

  File system with login authentication

Implement a simple file system with login authentication and access control - Construct a hash/salt/shadow based user/password creation system.

  Implement a standard sorted linked list class

Write C++ Program:Implement a standard SORTED linked list class. Be sure to include constructor/copy constructor, destructor, and assignment operator overload.

  Binary tree, print right view of it

Given a Binary Tree, print Right view of it. Right view of a Binary Tree is set of nodes visible when tree is visited from Right side.

  Write a program that asks the user to enter two numbers.

Starting Out with C++ Write a program that asks the user to enter two numbers.

  A linked list of your song structure in cd

The CD object should have a data member that is a linked list of your song structure that you have in CD.  The CD class needs a function that allows it to add a song to the object, that function would then append the song to that instance of the link..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd