C + + reads txt text content and saves the results to new text

Source: Internet
Author: User
Tags readfile

Learn to read a document step-by

1 //readFile.cpp: Defines the entry point of the console application. 2 3 4#include"stdafx.h"5#include <iostream>6#include <fstream>7#include <string>8 using namespacestd;9 Ten //extension: File copy One voidFileCopy (stringFile1,stringfile2) { AIfstreaminch(file1); -Ofstream out(file2); -     if(inch){ the         stringLine ; -          while(Getline (inch, line)) { -cout << Line <<Endl; -              out<< Line <<Endl; +         } -     } +     Else{ Acout <<"File not Exist"<<Endl; at     } - } - int_tmain (intARGC, _tchar*argv[]) - { -     //1. Progressive reading of TXT documents -     //Ifstream in ("E:\\workspace\\cpp\\readfile\\config.txt");  in     //string Line; -     //While (Getline (in,line)) {//read in data row by line and save the data in lines to     //cout << line << Endl; +     //} -  the     //2. Read a file and write the contents of the file to another file *     //string filePath = "e:\\workspace\\cpp\\readfile\\";//file path, absolute path here $     //Ifstream in (FilePath + "Config.txt"); Panax Notoginseng     //Ofstream Out (FilePath + "Result.txt"); -     //string Line; the     //if (in) { +     //While (Getline (in,line)) { A     //cout << line << Endl; the     //Out << line << Endl;//writes the content read from the config file to the result file +     //    } -     //} $     //else{ $     //cout << "File not Exist" << Endl; -     //} -      the     //3. Call the FileCopy method -     stringFilePath ="e:\\workspace\\cpp\\readfile\\";Wuyi     stringFile1 = FilePath +"Config.txt"; the     stringFile2 = FilePath +"Result.txt"; - fileCopy (file1,file2); Wu      -     return 0; About}

C + + reads txt text content and saves the results to new text

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.