C ++ study notes 9

Source: Internet
Author: User

 

Read a text file and write it to a target text file, changing all lowercase to uppercase and double-spacing the output text.

 

Read a text file and write it into the target file. The target file converts all lowercase letters into uppercase letters and outputs the text with double line spacing.

 

Name.txt

Fanzhaoxin
Bush will
Sadamu
Micro jaoden

 

// BookProgramAfter compilation and compilation under vcsp6, the user creates a name.txt file and writes the file to name2.txt.
# Include <fstream>
# Include <cstdlib>
# Include <iostream>
Using namespace STD;

Void double_space (ifstream & F, ofstream & T)
{
Char C;
Char D;
 
While (F. Get (c ))
{
If (C> = 'A' & C <= 'Z ')
{
D = c-32;
T. Put (d); // Replace the case
}
If (C = '\ n ')
{T. Put (C );
T. Put (c); // when a carriage return occurs, two carriage returns are output to achieve double line spacing.
}
If (C <97 & C! = '\ N' | C> 122 & C! = '\ N ')
T. Put (C );

}
}

Int main ()
{

Ifstream f_in;
Ofstream f_out;
 
F_in.open ("name.txt", IOS: In); // read a file with a name, in the TXT format.
F_out.open ("name2.txt", IOS: Out); // output a file with the name saved, with double line spacing. Replace lowercase with uppercase letters.
 

 
If (! F_in)
{
Cout <"cannot open" <Endl;
Exit (1); // can not open return wrong
}
If (! F_out)
{
Cout <"cannot open" <Endl;
Exit (1); // The same as f_in
}
Double_space (f_in, f_out); // use the function to achieve your goal
Return 0;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.