C++ 读取txt文本内容,并将结果保存到新文本
循序渐进学习读文件
// 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文本内容,并将结果保存到新文本的更多相关文章
- java读取txt文件内容
package read; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; public ...
- C#生成PDF文档,读取TXT文件内容
using System.IO;using iTextSharp.text;using iTextSharp.text.pdf; //需要在项目里引用ICSharpCode.SharpZipLib.d ...
- android 读取txt文件内容
Android的res文件夹是用来存储资源的,可以在res文件夹下建立一个raw文件夹,放置在raw文件夹下的内容会被原样打包,而不会被编译成二进制文件,并且可以通过R文件进行很方便地访问. 比如我们 ...
- Java 读取 txt 文件内容到容器 List
方法一: 一.桌面上准备 DataObject.txt 文件,内容为: 二.打开 Eclipse,编写代码如下: import java.io.BufferedReader; import java. ...
- JAVA 读取txt文件内容
原文地址https://www.cnblogs.com/xing901022/p/3933417.html 通常,我们可以直接通过文件流来读取txt文件的内容,但有时可能会出现乱码!此时只要设置一下文 ...
- C# 只读模式读取txt文件内容
读取txt文件时,提示异常: 文件“..\Log\all_info.txt”正由另一进程使用,因此该进程无法访问此文件 原因: 日志文件通过lognet生成的日志文件(C#使用log4net记录日志) ...
- Java代码一行一行读取txt的内容
public static void main(String[] args) { // 文件夹路径 String path = "E:\\eclipse work\\ImageUtil\\s ...
- php逐行读取.txt文件内容,并解析每行内容
// 读取nlp text 并存到mongodb public function readNLP(&$errorCode,&$errorMessage) { try{ // $_SER ...
- 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 ...
随机推荐
- Audio播放音效
AudioToolbox.framework是一套基于C语言的框架,使用它来播放音效其本质是将短音频注册到系统声音服务(System Sound Service).System Sound Servi ...
- tomcat7 日志设置为log4j
tomcat的日志设置用log4j的官方文档:http://tomcat.apache.org/tomcat-7.0-doc/logging.html 1. 下载tomcat-juli.jar, to ...
- 【Android】解决新建的xml文件无法正常加载的问题
新建一个xml布局文件,如下: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xm ...
- bat基础命令
rem 删除日志文件和catalina文件移动war包(下载了tomcat的一级目录下) del /q /s logs\*.* del /q /s webapps\moc.war rmdir /q / ...
- Linux C++线程池
.为什么需要线程池? 部分应用程序需要执行很多细小的任务,对于每个任务都创建一个线程来完成,任务完成后销毁线程,而这就会产生一个问题:当执行的任务所需要的时间T1小于等于创建线程时间T2和销毁线程时间 ...
- SpringMVC生成任意文件,访问链接即下载
原理上讲就是返回的 ResponseEntity<byte[]> 形式的值就可以了 @RequestMapping("/api/watermark_download") ...
- 1007. Maximum Subsequence Sum (25)
Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, ...
- JSP学习
http://blog.csdn.net/javaeeteacher/article/details/1932447
- Android BadgeView使用
BadgeView是第三方的插件,用来显示组件上面的标记,起到提醒的作用,下载地址如下:http://files.cnblogs.com/files/hyyweb/android-viewbadger ...
- LoadLibrary失败,GetLastError MOD_NOT_FOUND
即使传入的.dll文件存在,也可能返回这个错误.因为加载的DLL库可能以来其他库,尤其是编译器的dll. 以腾讯的debug版libtim.dll为例:如果没有msvcr100d.dll和msvcp1 ...