accountnumber型金额

15检查52.42

23节省51.51

11检查12.21

是我的标签已分列文件

我希望能够通过帐号搜索行。说如果我投入23,我想得到那行。ID如何做到这一点?

还更进一步,如果我想改变特定值,请在帐户23中说出51.51。如何获取该值并用新值替换它? 到目前为止,我只是按行读取行

字符串线; ifstream是(“account.txt”);

 if (is.is_open())
 {
while (std::getline(is, line))  // read one line at a time
{
    string value;
    string parseline;
    std::istringstream iss(line);

    getline(line, parseline);
    cout << parseline << endl;  // do something with the value
    while (iss >> value)    // read one value at at time from the line
    {
        //cout << line << "   ";    // do something with the value
    }
}
is.close();
 }
 else
     cout << "File cant be opened" << endl;

return 0;
.

有帮助吗?

解决方案

给定每行是可变长度,没有首先解析整个文件的特定行索引到特定行。

但我怀疑你的程序将想要操纵随机行和列。所以我首先解析整个文件。将每一行放入阵列中的自己的数据结构,然后在数组中索引该行。

您可以使用“strtok”将输入拆分为行,然后再次strtok将每行拆分为字段。

其他提示

如果我这样做,我将首先写一些解析整个文件的一些函数并将数据存储在适当的数据结构中(例如数组或std :: map)。然后我将使用数据结构进行所需的操作(例如搜索或编辑)。最后,如果有任何修改,我会将数据结构写回文件。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top