Jump to content
  • Advertisement
Sign in to follow this  
PGSCreativeDirector

how to search for more then once of the same contents in a text file?

This topic is 2478 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello im working out how to search for more then once of the same contents in a text file

Here is my explanation:


Here is my text file

this text file contains many lines of the same characters for example ".txt".

i want to be able to basically read the text file for every character that matches too this ".txt" and only that if .txt still exists in the text file still

heres a code example if you still don't get it


#include <iostream>

using namespace std;

int main()


if(string.find(".txt)) <- at this point i want to be able to keep doing this command how would i do this? and only that if .txt still exists in the text file still

{
""then do this stuff""
}



thank you

Share this post


Link to post
Share on other sites
Advertisement
You can pass the position to start looking for the substring ".txt" to the string::find method. So you store the last position and run a loop while the position is not equal to string::npos using the last found position (+1) as the starting point.

So it would look something like this:


size_t pos = inputString.find(".txt");
while(pos != string::npos) {
// do this stuff

// look for the next occurence of .txt
pos = inputString.find(".txt", pos+1) ;
}

Share this post


Link to post
Share on other sites
Can't say too much about that without knowing your code. How about building a list of occurences of .txt using the loop I posted and use that list as an input for your rendering routine?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!