I'm new to code blocks, and I can't seem to get it to work with command line arguments of < input > output. Does anyone know how to?
I'm currently able to read a file passed from argv[1] but, the program doesnt automatically read the input from the given file nor does it right the output to the file output.
I'm aware it is on set program's arguments, my arguments line is: list.txt < input > output
After some research I saw a guy doing it like this: < ./input > ./output, seems like running a program to give the input and output, anyways, I've also tried that to no avail. Do I need to use file handlers to interact with it? It doesn't make sence, simple getchar() should read from the passing input file.
What am I missing here?
Thanks in advance
I know this is an old topic, but none of the solutions are good enough. For Windows, I would probably go with the following macro definition (as you may need it also for debug printing or similar) at global scope
Then as the first or second line (if you need std::ios::sync_with_stdio(false); ) in main use it as
And define in Code::Blocks under Projects > Build Options... > (Debug, Compiler Settings, #defines)
Expecting that "input.txt" is the text input file in the folder where rest of the .c or .cpp files are, and "output.txt" will be the output file generated in the same folder (or they can be both added to the project as such files for easier editing/viewing).
This solution will work with both cin/cout and scanf/printf.
I've been working with Code::Blocks for some time now and just recently noted the same at least with Code::Blocks 12.11 in Windows. The redirections > and < do not work in the Project -> Set programs arguments...
A hackish solution is to do the execution in post-build step.
Right click
project name -> Build options... -> Pre/post build steps -> Post-build steps:
And check the checkbox Always execute, even if target is up-to-date. Now hit Ctrl+F9 and the program is executed as a last step of the building process.
I was able to get input redirected to my c program by setting program arguments in project menu.
Navigate to
Top Menu>Project>Set programs' arguments
and put</absolute/path/to/yourinputfile
notice<
in start it tricks codeblocks into redirecting file instead of passing argument.I tried almost all of the options & failed to make it work :P After becoming fed up with all that, I basically use file processing to get my work done ( phew )
here is what I did in the code
At global scope I wrote :
& in main I wrote the following before doing anything else:
Finally just before closing the main process did this :
After this added two files
&
to the project
This worked as expected
I have found a way how to do it in CB 13.12
It basicaly launches windows console and passes Parameters to it. You can also assign keyboard shortcuts to these tools. The only disadvantage i can see is that the tools are not project specific.
I think it is the problem of
cb_console_runner.exe
which launches your program in IDE.ConsoleRunner
can not interpret redirection symbol. So, I add some code to the original code of codeblocks 13.12. Please copy linked file to [cb folder]. (Don't forget back-up the original.)binary : http://limity.tistory.com/attachment/cfile30.uf@241A8D485621595131B28F.exe
source code : http://limity.tistory.com/attachment/cfile23.uf@231AF3485621595232A632.cpp