我想制作文本文件,如下所示:
car = "big"
couse = "small"
quality = 0
apple = "red"
然后从中读取..以便string car = "what";
和int quality = 1;
更改为"big"
和0
。
我不知道如何解决这个问题,因为我对C ++很新,即使我确定此问题已经被问过很多,但我找不到问题的答案。
答案 0 :(得分:1)
查看I/O with files的基础。
这个想法是加载一个文件,逐行读取,然后解析这些行,以便检索你的信息。
答案 1 :(得分:1)
扩展Djon,一些伪代码怎么样?
int main(int argc, char **argv)
{
// open file
// loop begin
// read in file, storing lines in an array (or vector) of strings
// loop end
// parse lines, to find the ones you want
// replace data in lines as you like
// delete original file
// create new version of file, with data in string vector
// close the file
// done!
}
遵循此算法,您应该能够解决您的问题。