How do you search for a string in a system? I am trying to make a program that does a system ping then returns to you only a portion of the results such as only the amount of packets loss. Any ideas on how to do that? What I had so far was to transfer the results to a text file then read the text file. But after that I am not sure how to extract a certain line from those results. Any help would be greatly appreciated.

Recommended Answers

All 3 Replies

You haven't really provided enough specific information.

What do you mean by "system" and "ping"? You've collected some sort of text packet over some socket into a file?

How is the string to be found? Can you search for an exact match? Or would something more flexible be required?

In either case, just read the file one line at a time and search each line for your match. If an exact match will do, use one of the std::string find functions. If you need something more complicated, check out Boost's regex library.

Hope this helps.

Well to clarify it, what I did so far is have the program send the system("") results to a text file then read the text file. What I am trying to do right now is search for a set of strings after I open the text file. Any suggestions?

create a loop to read each line into a std::string object, then call string's find method to see if that line contains the string you want to find.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.