[C + + standard library]_[0 base]_[using FStream to merge text files]

Source: Internet
Author: User


Scene:

1. Merge text files, and do not merge the first line from the 2nd file.

2. Add a feature that supports more than 2 file merges.

3. Question: http://ask.csdn.net/questions/192151



Just can say very easy: the foundation is just off, this classmate, also may not develop, put here also for training Foundation poor.

Test.cpp

#include <fstream> #include <string> #include <iostream>using namespace std;//The last parameter is the output file.// Support for extra 2 files Merge//use method, command line: Test.exe 1.txt 2.txt  output.txtint Main (int argc, char const *argv[]) {cout << usage1:t Est.exe 1.txt 2.txt output.txt "<< endl;cout <<" Usage2:test.exe 1.txt 2.txt ... output.txt "<< endl;if  (argc <= 3) return-1;bool first_line_readed = False;ofstream fout (argv[argc-1], ios::out); for (int i = 1; i< argc- 1; ++i) {ifstream fin (argv[i]), string str;int Line_number = 0;while (Getline (FIN,STR)) {if (!line_number) {if "!first_line_ readed) {first_line_readed = True;str.append ("\ n"); Fout.write (Str.c_str (), str.size ());}} Else{str.append ("\ n"); Fout.write (Str.c_str (), str.size ());} line_number++;}} cout << "Finish ..." << argv[argc-1] << endl;return 0;}


[C + + standard library]_[0 base]_[using FStream to merge text files]

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.