1
我是C++的新学习者。 我有一个文本文件,其内容如下一样:通过C++处理文本文件 - 从文本文件中提取某个字符串
Systemname localtesthost
SystemIp X.X.X.X
Systemowner root
...
现在我想提取“SYSTEMNAME”,那就是“localtesthost”的价值。
而且我可以提取包含“Systemname localtesthost”的行,但我不知道如何提取字符串“Systemname”。
下面是我的程序需要帮助:
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)
{
.
.
}
}
}
可以在任何一个告诉我如何提取字符串"localtesthost"
?
非常感谢!
尼姆,感谢您的方法。这比我想象的简单得多。谢谢! – zhaojing 2011-03-11 08:37:40
@赵靖,不客气! – Nim 2011-03-11 09:26:44