C++读取文件所有内容+写一个新文件
来源:互联网 发布:淘宝怎么上掌柜热卖 编辑:程序博客网 时间:2024/05/16 11:50
CStdString strForbiddenFilePathName = strModulePathName + "forbbiden.dat" ;
myFile.open(strForbiddenFilePathName.c_str()) ;
if (!myFile)
{
g_Log.GetLog()->WriteDBGLog(IMP_RECORD, "CWebPageAnalyze::GetArtical", strPreLog + "打开禁用关键词失败");
return FALSE ;
}
else
{
while(getline (myFile, strTemp))
{
arrWebForbiddenWord.push_back(strTemp) ;
strTemp.clear() ;
}
}
myFile.close() ;
myFile.clear() ;
2. // 注:下面的代码中CStdString不是C++的内置类型,如果要复制,请相应更改成string等。有些函数是本人自己写的,也要相应删除。
ifstream myFile1 ;
string strTemp1 ;
CStdString strUrl = strModulePathName + "url.txt" ;
myFile1.open(strUrl.c_str()) ;
ofstream myFileOut1;
CStdString strExtractContent = strModulePathName + "ExtractContent.txt" ;
myFileOut1.open(strExtractContent.c_str()) ;
strTemp1.clear() ;
while (getline(myFile1, strTemp1))
{
TestAnalyze.GetArtical(strTemp1, strMyTitle, strMyContent) ;
myFileOut1<<strTemp1.c_str()<<endl<<strMyTitle.c_str()<<"##"<<endl<<strMyContent.c_str()<<endl<<"####"<<endl ;
strTemp1.clear() ;
strMyTitle.clear() ;
strMyContent.clear() ;
}
myFile1.close() ;
myFile1.clear() ;
myFileOut1.close() ;
myFileOut1.clear() ;
另一个例子:
ofstream a ;
a.open ("1.txt") ;
DWORD I = GetTickCount () ;
for (int i =0; i<10000; ++i)
a<< 2011 << "-" << 8 << "-" << 3 << " " << 14 << ":" << 22 << ":" << 59
<< "\t" << "172.17.17.11" << "\t" << "49801bcf518c445 " << "\t" << "logvertest.exe"
<< "\t" << "Administrator" << "\t" << "无" << "\t" << "Run"
<< "\t" << "neirong" << "\t" << "Warn" << "\r\n";
DWORD II = GetTickCount () - I ;
注意:直接写数字的花费的时间比写字符的快。如 写8 比 写"08"快。
- C++读取文件所有内容+写一个新文件
- 创建一个文件,写进内容,拷贝新文件
- C读取文件内容
- [QTP]通过vbscript读取一个文件中的所有内容
- C语言逐行读取文件内容,写入另外一个文件
- C++ 写文件及读取文件内容
- php读取一个文件内容
- 如何读取一个文件并将内容写入一个新文件中
- 二进制读取文件内容[C#]
- C格式读取文件内容
- C语言读取文件内容
- 一次读取文件中所有内容
- 一次读取文件中所有内容
- 读取文件夹下所有文件内容
- 读取文件内容并替换内容后生成新文件
- Python 读取文件替换其中的内容并输出到一个新的文件内
- Java8 新API读取文件内容
- c语言 读取文件内容 文件写入
- 工具集合及使用方法
- 关于win7_iis报500.19和500.21错误的解决方法
- 调色板的原理
- js实现树形菜单效果
- vistor模式
- C++读取文件所有内容+写一个新文件
- Erlang Tips:如何检查目标进程已经启动
- 消息中间件与WebsphereMQ入门
- 手把手配置hibernate环境
- 一块网卡绑定多个ip,在单一网卡服务器上运行多个基于ip的虚拟主机
- Build Your Programming Technical Skills
- js 数字的进制表示
- ACM/ICPC Java高精度计算
- BFS 蛇和梯子 HUNNU