Code Blocks redirecting input output

后端 未结 6 1851
被撕碎了的回忆
被撕碎了的回忆 2020-12-16 04:58

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

6条回答
  •  醉话见心
    2020-12-16 05:40

    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 :

    #define DEBUG
    
    #ifdef DEBUG
    #include
    
    ifstream Inputfile;
    ofstream Outputfile;
    
    #define cin     Inputfile
    #define cout    Outputfile
    
    #endif  //#ifdef DEBUG
    

    & in main I wrote the following before doing anything else:

    int main(){
    #ifdef DEBUG
    
        Inputfile.open("Input.txt");
        Outputfile.open("Output.txt");;
    
    #endif // #ifdef DEBUG
    

    Finally just before closing the main process did this :

    #ifdef DEBUG
    
        Inputfile.close();
        Outputfile.close();
    
    #endif // #ifdef DEBUG
    

    After this added two files

    Input.txt

    &

    output.txt

    to the project

    This worked as expected

提交回复
热议问题