【发布时间】:2019-02-07 18:39:15
【问题描述】:
我尝试编写一个从 .txt 文件中检索数据并在终端中显示的小程序,但出现错误。 我不得不说我是视觉工作室的新手;到目前为止,我一直在研究代码:块
我已经尝试了错误代码中的建议,在开头添加了#include“pch.h”,但它仍然不起作用。
错误代码是 C1010(如果我构建的代码没有 #include "pch.h" 行);如果我用该行构建它,我会收到多个错误代码:
"1>c:\users\bogdan\documents\c & c++ programs\writing and reading a txt file\writing and reading a txt file\writing and reading a txt file.cpp(10): error C2065: 'ifstream': undeclared identifier
1>c:\users\bogdan\documents\c & c++ programs\writing and reading a txt file\writing and reading a txt file\writing and reading a txt file.cpp(10): error C2146: syntax error: missing ';' before identifier 'inFile'
1>c:\users\bogdan\documents\c & c++ programs\writing and reading a txt file\writing and reading a txt file\writing and reading a txt file.cpp(10): error C2065: 'inFile': undeclared identifier
1>c:\users\bogdan\documents\c & c++ programs\writing and reading a txt file\writing and reading a txt file\writing and reading a txt file.cpp(11): error C2065: 'inFile': undeclared identifier
1>c:\users\bogdan\documents\c & c++ programs\writing and reading a txt file\writing and reading a txt file\writing and reading a txt file.cpp(11): warning C4129: 'B': unrecognized character escape sequence
1>c:\users\bogdan\documents\c & c++ programs\writing and reading a txt file\writing and reading a txt file\writing and reading a txt file.cpp(11): warning C4129: 'D': unrecognized character escape sequence
1>c:\users\bogdan\documents\c & c++ programs\writing and reading a txt file\writing and reading a txt file\writing and reading a txt file.cpp(14): error C2065: 'inFile': undeclared identifier
1>c:\users\bogdan\documents\c & c++ programs\writing and reading a txt file\writing and reading a txt file\writing and reading a txt file.cpp(15): error C2065: 'cout': undeclared identifier"
#include "pch.h"
#include <iostream>
#include <fstream>
#include <string>
int main()
{
ifstream inFile;
inFile.open("C:\Users\Bogdan\Documents\UID.txt");
int x;
inFile >> x;
cout << x;
return 0;
}
【问题讨论】:
-
请告知错误代码/文本是什么。
-
你需要转义你的\所以用\\替换\
-
对不起,我的错,我忘了说。代码是C1010(如果我构建的代码没有#include“pch.h”行);如果我用该行构建它,我会收到多个错误代码:
-
在询问构建错误时,请务必完整完整地包含 实际 错误,包括任何可能的信息说明。并复制粘贴为文本。所以请编辑您的问题以包含它。
-
@Someprogrammerdude 我重写了我的问题