zha*_*ing 1 c++ string getline substr strtok
我是C++的新学习者.我有一个文本文件,其内容如下:
Systemname localtesthost
SystemIp X.X.X.X
Systemowner root
...
Run Code Online (Sandbox Code Playgroud)
现在我想提取"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)
{
.
.
}
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我如何提取字符串"localtesthost"吗?
非常感谢!
这是一种方法:
std::istringstream使用您刚读入的行创建一个.std::string对象,键和值| 归档时间: |
|
| 查看次数: |
1777 次 |
| 最近记录: |