"Project 4-programs to process C + + source Code" (3)

Source: Internet
Author: User

Problem Description:

(3) read into a C + + program, enter m, n two digits, the n lines of code from line m will be used as a comment (that is, precede these lines with "//"), the new program is saved to another. cpp file, and the program is displayed with a line number on the screen.

Code implementation:

#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <    Fstream>using namespace Std;int Main () {FStream my1 ("Source.cpp");        if (!my1) {cerr<< "can ' t find source.cpp!\n";    Exit (1);    } ofstream my2 ("Newsource.cpp");        if (!my2) {cerr<< "can ' t write the newsource.cpp!\n";    Exit (1);    } int n,m;    printf ("Please enter M and N, will make the n lines of code from line m of the program be used as comments \ n");    scanf ("%d%d", &m,&n);    int i=1;    string S;        while (!my1.eof ()) {getline (my1,s);            if (i>=m&&i<= (m+n)) {my2<< "\ \";            my2<< "\";        } my2<<s<< ' \12 ';    i++;    } my1.close ();    My2.close ();    FStream in ("Newsource.cpp");        if (!in) {cerr<< "can ' t find newsource.cpp!\n";    Exit (1);    } printf ("\n\nwatch the newsource.cpp\n\n\n");        while (!in.eof ()) {getline (in,s);    cout<<s<< ' \12 '; } return 0;}

Operation Result:


"Project 4-programs to process C + + source Code" (3)

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.