我正在制作一种机器人,我需要从文档中获取一些值。该文档将写入一些“首次设置”。好吧,问题是程序没有读取值。
ifstream inFile;
inFile.open("D:\Bot\bin\Debug\Settings.in");
inFile >> i >> i2;
cout<<"Retrieving data..."<<endl;
cout<<" "<<endl;
Sleep(10000);
cout<<"SO: "<<i<<endl;
cout<<"BO: "<<i2<<endl;
Sleep(2000);
inFile.close();
我使用了 .exe 所在的位置。我不明白为什么它没有获得值(value)。我的两个变量都为 0。我尝试使用 .txt 文件。同样的事情。
最佳答案
\是转义符。要将其放入字符串中,它应该是:
inFile.open("D:\\Bot\\bin\\Debug\\Settings.in");
关于c++ - ifstream 在我的代码中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32075855/