I am a new learner to C++.
I have a text file, its contents like following:
Systemname localtesthost
SystemIp X.X.X.X
Systemowner root
...
Now I want to extract the value of “Systemname”, that is “localtesthost”.
And I can extract the line containing “Systemname localtesthost”, but I don’t know how to extract the String “Systemname”.
Below is my program need help:
const char* configInfoFile = "config_info";//the text file name
ifstream ifs(configInfoFile);
string line;
while(getline(ifs,line)) {
if(line.length() > 0){
int index = line.find("SystemName");
if (index != -1)
{
.
.
}
}
}
Could any one show me how to extract the string "localtesthost"?
Many thanks!
Here is an approach:
std::istringstreamusing the line you just read in.std::stringobjects, key and value