I tried to write a little program that retrieves data from a .txt file and shows it in the terminal but I got an error. I have to say I am new to visual studio; until now i worked on code:blocks
I have tried the suggestion from the error code, adding the #include "pch.h" at the beggining but it still didn t work.
The error code is C1010 (if i build the code without line #include "pch.h"); If i build it with that line i recieve multiple error codes:
"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; }