C++ file operations: opening and writing files

    #include<fstream>
 #include<iostream>
 #include<iomanip>
 using namespace std;

 int main(){

    char a[28];

    int i =0;

    ifstream iffile; //Describe the input file stream object ifile
    ofstream offile; //Describe the output file stream object offile

     ifile.open( "d:\\my_in_file.txt" );
    ofile.open( "d:\\my_out_file.txt" );


   ifstream iffile( "d:\\my_in_file.txt" ); //Describe the input file stream object ifile and open the file
    ofstream offile( "d:\\my_out_file.txt" ); //Describe the output file stream object offile and open the file

    oflie<<"Output information"<<endl;

     if (!ifile)//Determine whether the file exists;
{
printf("The corresponding file was not found");
ifile.close();
system("pause");
return 0;
}
while (1)
{
while (ifile.get(a[i]))
{
if (a[i] == '\n')break;
i++;
}
a[i] = '\0';
printf("%s\n", a);

i = 0;

if (ifile.eof()!=0)
{
break;
}
}

 ifile.close();  

 return 0;

}

Just as a simple memory, it is considered to be copied from the predecessors, and the specific keywords are all there, the main thing is how to master this kind of knowledge in the actual application process;


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326740949&siteId=291194637