I have successfully installed MinGW and have tried running cpp programs from command prompt and it runs perfectly. In Sublime I tried using default build system ‘C++ Single File’, it prints simple statements in the console below but it cannot take input. After building the programs with ‘cin’ commands the program does not show any output and I try giving input in the console below and press ENTER but nothing happens. Then I found a method of using ‘freopen’ command to take input from a file and output to a different file. But the programs runs successfully but doesn’t output anything in the output file. Same problem – mingw64 + sublime 3 input output files not working
After this I tried many other build files I found on web but none of them work.
{
"cmd": ["g++.exe", "-std=c++17", "${file}",
"-o", "${file_base_name}.exe",
"&&", "${file_base_name}.exe<input.in>output.out"],
"shell":true,
"working_dir":"$file_path",
"selector":"source.cpp"
}
The output.out file is always empty. I have input and output files in same directly and I think it is reading input correctly because when I delete the input file it gives an error that it cannot find the input file. I even tried using text files (input.txt, output.txt) after moding build system code but it doesn’t work. I have many other build codes but none of them works. I tried running g++.exe -std=c++17 contest1a.cpp -o contest1a.exe && contest1a.exe<input.in>output.out
in command prompt but the output.out file is still empty. I replaced first line with "cmd" : ["g++ -std=c++14 $file_name -o $file_base_name && timeout 4s $file_base_name < input.in > output.out"],
but it gives error because I think .exe is not suffixed which I tried adding and program runs but output is still empty.
Why is ‘freopen’ not working, why is any build not able to write in output file ?