I want to extract the strings string1 and string2 from the line:
config.?.getstring=("string1,string2");
This line is in another file. There are 100 other lines like this in the file that start with config but only "getstring" is unique. My program should not be aware of what string1 and string2 nor how many strings there are.
My program should pick up string1, sring2 etc and assign variables to them.
My code so far:
Expand|Select|Wrap|Line Numbers
- #include <fstream>
- #include <iostream>
- #include <string>
- using namespace std;
- using std::string;
- int main()
- {
- string tmp = "getstring";
- string tmp1;
- fstream file_op("/path/of/file",ios::in);
- if (!file_op)
- {
- cout << "cant open file\n";
- return 1;
- }
- while (! file_op.eof())
- {
- getline(file_op,tmp1);
- cout << tmp1 << endl;
- //string tmp2; not working says return type should be char!
- // tmp2 = strstr (tmp1, tmp);
- // cout << tmp2 << endl;
- // string sub = theline.substr(18);
- // string tokens = strtok(sub," ,)(;");
- // cout << sub << "\n";
- }
- file_op.close();
- return 0;
- }
I am struggling with the strstr function. Also i dont know how i am supposed to find out the number of strings in that line and assign variables to them.
Please assist
Thank you