954,190 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Search a txt file for words

hi all , i have a txt file called myfile.txt , i want to open this file and search for the following
" this page is good/"

if i find this i want to read every thing after "/" until i reach so for example

this page is good/so i want to copy this

dont mind my question but i really dont know much in C++


thanks for your great help

taha54
Newbie Poster
3 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
 

any help???

taha54
Newbie Poster
3 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
 

1. Open file
2. Retrieve data in a string
3. Compare
4. Once you find a match then read again till you find first

Grunt
Junior Poster
152 posts since Jul 2006
Reputation Points: 197
Solved Threads: 12
 

i need the code for that , i really dont know alot in C++

taha54
Newbie Poster
3 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
 

We really don't like to write whole programs or routines for people. Here's a quick overview with a little more detail than p;rovided by Grunt. As you can tell, there are several choices you will have to make depending on what you know and don't know.

The phrase you are looking for is called a string. The file you are searching can be opened and read in as a sequence of strings or as a single string. You will then need to search for the string(s) from the file for the desired string. If found, the desired string is called a substring of the whole string. There are several ways to search for a substring depending on the type of string you use. You could use strstr() if you use C style strings, and I'm sure that the STL library will have functions to search for substrings as well, either in the string library itself or in the algorithm library. It would also be instructive to write your own function to familiarize yourself with the workings of strings. Last, but not least, if you aren't familiar with the concept of strings at all, then this project is beyond your scope of programming at this point and you should set your sights a little lower for now---like learning about strings, working with files, etc.

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

Show some effort. I don't think anyone here will give you code this way.

Grunt
Junior Poster
152 posts since Jul 2006
Reputation Points: 197
Solved Threads: 12
 

Look into string methods, like .find(), .delete(), etc.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,492 posts since May 2006
Reputation Points: 3,348
Solved Threads: 943
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You