In order to read input from a text file, I wrote the following code:
int main(){
int x;
#ifndef ONLINE_JUDGE
freopen(\"input.txt\", \"r\", stdin);
#e
I would give you an alternate way. If you still want to use freopen, you can use "-D _CRT_SECURE_NO_WARNINGS" this option with the terminal command, the error message will be suppressed.
In VS you can add it under the following link -
Project-> "Project" Properties -> C/C++ -> Command Line -> Additional Options(Text box on bottom right).
This should resolve the issue!
I would suggest you to avoid using the C style I/O library and use IOSTREAM Library. Its more safe and clean solution. Here is the sample code which opens a file and reads each line into the "std::string" object and prints on the console.
int main()
{
std::string file = "input.txt";
std::string line;
std::ifstream text_filestream(file.c_str());
while(std::getline(text_filestream, line)) {
std::cout<<line<<std::endl;
}
}