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

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

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 on other sites
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 on other sites
i get it but i dont get how to implement that into my code since every time it finds .txt i want it to show a opengl rendered quad representing the existence of a txt file

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?

• 10
• 19
• 14
• 19
• 15