--17th Chapter "CPP" Input output and file
01
#include <iostream>#include<cstring>intMain () {usingstd::cout; usingStd::endl; Const Char*state1="Florida"; Const Char*state2="Kansas"; Const Char*state3="Euphoria"; intlen=Std::strlen (STATE2); cout<<"increasing loop index:\n"; inti; for(i=1; i<=len;i++) { cout.write (state2,i); cout<<Endl; } cout<<"decreasing loop index:\n"; for(i=len;i>0; i--) {cout.write (state2,i)<<Endl; } cout<<"exceeding string length:\n"; Cout.write (State2,len+3) <<Endl; return 0; }
02
#include <iostream>intMain () {using namespacestd; cout<<"Input a integer:"; intN; CIN>>N; cout<<"N n*n\n"; cout<<n<<" "<<n*n<<"(decimal) \ n"; cout<<Hex; cout<<n<<" "<<n*n<<"(hexadecimal) \ n"; cout<<oct<<n<<" "<<n*n<<"(octal) \ n"; Dec (cout);//restore original output formatcout<<n<<" "<<n*n<<"(decimal) \ n"; return 0; }
03
#include <iostream>//Auto FillintMain () {usingstd::cout; Cout.fill ('*'); Const Char*number[5]={" the","No.2","No.3","No.4","No.5"}; Longbonus[5]={ +,1350,820, -,980}; for(intI=0;i<5; i++) {cout<<number[i]<<":$"; Cout.width (7); cout<<bonus[i]<<"\ n"; } return 0; }
04
#include <fstream>#include<iostream>#include<cmath>#include<cstdlib>using namespacestd; //////////////function to read characters from the keyboardvoidRead_save () {Charc[ the]; Ofstream outfile ("Data1.txt");//Open the file with the output worker if(!outfile) {Cerr<<"Open error!"<<endl;//Note that it's cerr.Exit1); } cin.getline (c, the);//reads a line of characters from the keyboard for(intI=0; c[i]!=0; i++)//one-to-one processing of characters until '/0 ' is encountered if(c[i]>= $&&c[i]<= -|| c[i]>= the&&c[i]<=122){//guarantees that the characters entered are charactersOutfile.put (C[i]);//save alphabetic characters to disk filecout<<c[i]<<""; } cout<<Endl; Outfile.close (); } voidCreat_data () {Charch; Ifstream infile ("Data1.txt"Ios::inch);//Open the file as input if(!infile) {Cerr<<"Open error!"<<Endl; Exit (1); } ofstream outfile ("After.txt");//defining the output stream F3.dat file if(!outfile) {Cerr<<"Open error!"<<Endl; Exit (1); } while(infile.Get(CH)) {//When you read the word Fu Chenggong if(ch<=122&&ch>= the) Ch=ch- +; Outfile.put (CH); cout<<ch; } cout<<Endl; Infile.close (); Outfile.close (); } intMain () {read_save (); Creat_data (); System ("Pause"); return 0; }
Heart Tired 、、、
"C + + learning • Several snippets of code" Day 1