C / C ++ input and output redirection

My first blog yo, in memory of:

  I saw other people beautiful theme, just think the words written with word save up too much trouble, there is hope that more exchanges with you (of course, my main thing is to see for himself);

I have knowledge while (1) cout << "very"; limited, if you see that I have any mistakes or shortcomings, really really really urge you pointed out, crab, and I hope we can progress together ~

Well, no nonsense.

 

Redirect

  What is Redirect? I do not beep miles it will be a bunch of friends, and I will not say more, I say is the following:

After written C, C ++ programs, data input into the text file, and the data entry program which, at the same time, you can also output data to a file to which the program by using the text file;

It is not that much good? Do I file it can not be operated through the program?

Can be, but this is too much trouble, each program should write again, moreover, if it is time to forget to delete the game how to do?

In fact, redirect input output large role, especially for a large amount of input and output data when the game program is also ideal for other occasions, more importantly, is very convenient;

 

emmm, I do not know spade? Do not seem to know what introduced, then get to the bar:

Below to the digital mobile demonstration program:

1  / * * after the digital shift * / 
2 #include <stdio.h>
 . 3  int Data [ 100 ];
 . 4  // inverting function, the data [start] to data [end] data inversion 
. 5  int the swap ( int Start, int End) {
 . 6      int I, J;
 . 7      int TEMP = 0 ;
 . 8      the while (End> Start) {
 . 9          TEMP = Data [Start];
 10          Data [Start] = Data [End];
 . 11          Data [End] = TEMP ;
 12          Start ++, end--;
 13 is      }
 14  }
 15  
16  int main () {
 . 17      int n-, m; // number of digits and the number of backward 
18 is      int I, J;
 . 19      Scanf ( " % D% D " , & n-, & m); 
 20 is      for (I = 0 ; I <n-; I ++ ) {
 21 is          Scanf ( " % D " , & Data [I]); 
 22 is      }
 23 is      the swap ( 0 , N- . 1 -m); //
 24      the swap (nm, N- . 1 );
25     swap(0,n-1);
26     for(i=0;i<n;i++){
27         printf("%d ",data[i]);
28     }
29     return 0;
30 } 

 

This is an executable file obtained after compilation:

This is a program run shot :( data directly from the console input)

 

Input redirection:

  1. shift + right mouse button, click on "Open command window here" :( or open cmd and then go to the next directory stored procedure)

   

   

  2. Under the new catalog store input data text file "test.txt", and its input data:

   

  3. Enter " file name <name input data file ", and press Enter, such as:

   

Redirect the output:

  1 is simple, and almost redirection, enter " file name> name of the output data file " (if the file does not exist automatic generation), the following is used with the redirector:

   

   

Precautions:

  1. Redirection symbols ">", "<" is the direction of the redirection, may also be followed to redirect the output symbol ">>", which represents an additional, i.e., the file does not overwrite the original content, and ">" overrides, such as :

   

   

  Changed to ">>" once again after the execution, out.txt in storage before the results of the implementation and results of the execution;

   

   

  The original results of the two is overwritten, the operating results of this deposit;

Epilogue

  That is about all, though very simple, because always forget how to use, and very difficult to find online, so record it, easy to find;

I am grateful kiss can read so much nonsense, love you yo, Meme da ~!

Guess you like

Origin www.cnblogs.com/ChaseMeng/p/12624136.html