循序渐进学习读文件

 // readFile.cpp : 定义控制台应用程序的入口点。

 #include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std; //引申:文件拷贝
void fileCopy(string file1,string file2){
ifstream in(file1);
ofstream out(file2);
if(in){
string line;
while(getline(in,line)){
cout << line << endl;
out << line << endl;
}
}
else{
cout << "File Not Exist" << endl;
}
in.close();
out.close();
}
int _tmain(int argc, _TCHAR* argv[])
{
//1.逐行读取TXT文档
//ifstream in("E:\\workspace\\CPP\\readFile\\config.txt");
//string line;
//while(getline(in,line)){//逐行读取in中的数据,并把数据保存在line中
// cout << line << endl;
//}
//in.close(); //2.读取一个文件,并将文件内容写入到另一个文件中
//string filePath = "E:\\workspace\\CPP\\readFile\\";//文件路径,此处为绝对路径
//ifstream in(filePath + "config.txt");
//ofstream out(filePath + "result.txt");
//string line;
//if(in){
// while(getline(in,line)){
// cout << line << endl;
// out << line << endl;//把从config文件中读取的内容写到result文件中
// }
//}
//else{
// cout << "File Not Exist" << endl;
//}
//in.close();
//out.close(); //3.调用fileCopy方法
string filePath = "E:\\workspace\\CPP\\readFile\\";
string file1 = filePath + "config.txt";
string file2 = filePath + "result.txt";
fileCopy(file1,file2); return ;
}

C++ 读取txt文本内容,并将结果保存到新文本的更多相关文章

  1. java读取txt文件内容

    package read; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; public ...

  2. C#生成PDF文档,读取TXT文件内容

    using System.IO;using iTextSharp.text;using iTextSharp.text.pdf; //需要在项目里引用ICSharpCode.SharpZipLib.d ...

  3. android 读取txt文件内容

    Android的res文件夹是用来存储资源的,可以在res文件夹下建立一个raw文件夹,放置在raw文件夹下的内容会被原样打包,而不会被编译成二进制文件,并且可以通过R文件进行很方便地访问. 比如我们 ...

  4. Java 读取 txt 文件内容到容器 List

    方法一: 一.桌面上准备 DataObject.txt 文件,内容为: 二.打开 Eclipse,编写代码如下: import java.io.BufferedReader; import java. ...

  5. JAVA 读取txt文件内容

    原文地址https://www.cnblogs.com/xing901022/p/3933417.html 通常,我们可以直接通过文件流来读取txt文件的内容,但有时可能会出现乱码!此时只要设置一下文 ...

  6. C# 只读模式读取txt文件内容

    读取txt文件时,提示异常: 文件“..\Log\all_info.txt”正由另一进程使用,因此该进程无法访问此文件 原因: 日志文件通过lognet生成的日志文件(C#使用log4net记录日志) ...

  7. Java代码一行一行读取txt的内容

    public static void main(String[] args) { // 文件夹路径 String path = "E:\\eclipse work\\ImageUtil\\s ...

  8. php逐行读取.txt文件内容,并解析每行内容

    // 读取nlp text 并存到mongodb public function readNLP(&$errorCode,&$errorMessage) { try{ // $_SER ...

  9. grails框架中读取txt文件内容将内容转换为json格式,出现异常Exception in thread "main" org.json.JSONException: A JSONObject text must begin with '{' at character 1 of [...]

    Exception in thread "main" org.json.JSONException: A JSONObject text must begin with '{' a ...

随机推荐

  1. python 拾贝

    1. 内建的 type() 函数带三个参数时, 将作为强悍的动态类构造器. 如下:   type(name, bases, dict) 返回一个新的type对象. 基本上是 class 语句的动态形式 ...

  2. Allegro 导入DXF文件,保留布好的线路信息

    最近智能钥匙产品开发过程中,由于结构装配尺寸的偏差,需要对电路PCB外框OUTLINE进行缩小调整,并且USB插座定位孔改变. Allegro软件在线性绘制方面是有严重缺陷的,想绘制一个异形的板框比较 ...

  3. 【Android 疑难杂症1】android.content.ActivityNotFoundException: Unable to find explicit activity class

    android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.cnote ...

  4. IOS7 edgesForExtendedLayout

    在iOS 7中,苹果引入了一个新的属性,叫做[UIViewController setEdgesForExtendedLayout:],它的默认值为UIRectEdgeAll.当你的容器是naviga ...

  5. IO流-字节输出流OutputStream异常处理

    package it.cast_01; import java.io.FileNotFoundException; import java.io.FileOutputStream; import ja ...

  6. JArray数组每个JObject对象添加一个键值对

    JArray ja = new JArray(); JObject jo = new JObject(); jo.Add("1","1"); ja.Add(jo ...

  7. VS.Net 2015 Update3 学习(1) 支持Webpack

    让vs.net 编译的时候自动执行webpack 首先 管理员模式下打开 “Developer Command Prompt for VS2015", 是管理员模式啊! 然后进入 cd c: ...

  8. spring cloud资料

    https://segmentfault.com/a/1190000006216281 http://git.oschina.net/zhou666/spring-cloud-7simple zuul ...

  9. thinkphp发邮件失败原因

    使用phpmailer出现连接失败, 代码是别人已经封装好的没有问题,可能原因有如下. qq提示: SMTP server error: mail from address must be same ...

  10. Nginx的第一个模块-HelloWorld

    麻雀虽小,五脏俱全,小小的Hello World盛行于程序世界,就在于其代码虽短,但要真正运行起来,需要我们略通基本语法,稍懂编译运行环境,知晓操作过程,最后,还有一颗持之以恒,不怕折腾的心.前一阵子 ...