-6

file content:

/function name: input\n\t\tworking: inputs details\n\t\t/

/*fuction name: datawrite\n\t\tworking: write the data into the file */

/function name: dataread\n\tworking: read the data in the file for display/

/*funtion name: accsummary\n\t\tworking: display the content of the file of specific person */

I want to extract only the "function names" and the "workings" from the file and store them into the array of string. "using c++" that is, if i have declared an array of string function[10] then this should store "input,datawrite,dataread,accsummary" similarly from "working"

  • hey, what have you tried? – Shubham Agrawal Jun 14 '17 at 05:25
  • i m not getting any idea , where to start and what to to do... – Varun Pathak Jun 14 '17 at 05:26
  • 3
    Ah. The best place to start is with a pen and paper, breaking the problem down into a list of all the things you need to do. If you do not know how to accomplish an item on this list, break it down into smaller problems until you do know how to accomplish it. If you literally do not know how to do anything, you need to start with a simpler assignment and [a good introductory book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) and learn the basics before proceeding. – user4581301 Jun 14 '17 at 05:32

2 Answers2

0

You need to take a look at the std::stringstream class: http://www.cplusplus.com/reference/sstream/stringstream/

Then you need to look at the substr method in std::string: http://www.cplusplus.com/reference/string/string/substr/

snoopy
  • 328
  • 1
  • 12
  • `stringstream` often eliminates the need for `substr` as you can easily [use `std::getline`](http://en.cppreference.com/w/cpp/string/basic_string/getline) and change the delimiter as required. – user4581301 Jun 14 '17 at 05:35
0

This sounds like a task for regular expression. In C++ there is support for regex especially regex_match. I guess, this should get you started. But be warned, what you are trying to accomplish will not be solved by simple regex.
Your matching string might look something like this

/\/function name: ([^\\]*).*/

This will look for string "function name: " followed by any character other than \ . and then any character up to the end of the line. The second part will be remembered and can be accessed by regex_match.

Try it in online regex tester and modify it based on your specific needs. Just note that it takes regex without leading and ending /.

Oh, I noticed that you asked also for extracting workings, while my example extracts only function names. But you will get there when you get the concept.

Marek Vitek
  • 1,573
  • 9
  • 20