#include"stdafx.h"
#include <iostream>
#include <windows.h>
using namespace std;
const int BUF_SIZE = 1024;
int main(int argc, char *argv[])
{
HANDLE fileIn, fileOut;
char buf[BUF_SIZE];
DWORD nread,nwrote;
if ((fileIn = CreateFile(_T("d:/test.txt"), GENERIC_READ,
0, 0, OPEN_EXISTING, 0, 0)) ==
INVALID_HANDLE_VALUE)
{
cerr << "Error opening source: " <<
GetLastError() << endl;
exit(1);
}
if ((fileOut = CreateFile(_T("d:/tttt.txt"), GENERIC_WRITE,
0, 0, CREATE_NEW, 0, 0)) ==
INVALID_HANDLE_VALUE) {
cerr << "Error opening destination: " <<
GetLastError() << endl;
exit(2);
}
while (ReadFile(fileIn, buf, BUF_SIZE,
&nread, NULL) && nread > 0)
{
if ( ! WriteFile(fileOut, buf, nread,
&nwrote, NULL))
{
cerr << "Error writing" <<
GetLastError() << endl;
}
}
CloseHandle(fileIn);
CloseHandle(fileOut);
exit(0);
return 0; // never reached
}
/*
#include"stdafx.h"
#include<fstream>
#include<vector>
#include<string>
#include<iostream>
using namespace std;
int main()
{
const char filename2[]="d:/Picture_of_switch_diagnostics_stack1_prerun.txt";
ofstream o_file;// 输出流:将数据从内存输出其中ofstream是将数据输出到文件,因此对于文件来说是“写”
string out_text;
//写
o_file.open(filename2);
string filename="d:/switch_diagnostics_stack1_prerun.txt";
fstream in(filename.c_str());//打开
char str;
vector<char>ivec;
vector<char>svec;
for( ;in.get(str); )
{//放入向量
ivec.push_back(str);
}
//svec.push_back(ivec[0]);
cout<<"size of ivec: "<<ivec.size();
for(int i = 0;i<ivec.size()-1;i++)
{
//if(ivec[i].find_first_of("YRI")!=string::npos)
if(ivec[i]=='S'&& ivec[i+1]=='t'&&ivec[i+3]=='t'&&ivec[i+4]=='u'&&ivec[i+5]=='s'&& ivec[i+7]=='O')
{
svec.push_back(ivec[i]);//换行后即为第一个,放入另外一个向量
o_file<<ivec[i]<<ivec[i+1]<<"\n";
}
}
for(int i = 0;i<svec.size();i++)
{
// cout<<svec[i]<<"\n";//如果要输出数字,加上(int)在svec[i]前面
}
o_file.close();
system("pause");
}
*/
/*
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
const char filename[]="d:/switch_diagnostics_stack1_prerun.txt";
ofstream o_file;// 输出流:将数据从内存输出其中ofstream是将数据输出到文件,因此对于文件来说是“写”
ifstream i_file;//将数据输入到内存,其中ifstream是说输入的数据在文件中,因此对于文件来说是“读”
string out_text;
//写
o_file.open(filename);
for(int i =0;i<=12;i++)
{
o_file<<"第"<<i<<"行\n";//将内容写入文本
}
o_file.close();
//读
i_file.open(filename);
if(i_file.is_open())
{
while(i_file>>out_text)
{
cout << out_text << endl;
}
}
else
cout<<"打开文件:"<<filename<<"时出错!";
i_file.close();
system("PAUSE");
return 0;
}
*/
/*
#include "stdafx.h"
#include <windows.h>
//test_utf8.txt的内容是四个汉字:“中文测试”
//一共占据15个字节,分别是:
//EF BB BF E4 B8 AD E6 96 87 E6 B5 8B E8 AF 95
//其中“EF BB BF”为BOM(Byte Order Mark),之后每个汉字占3个字节
int _tmain(int argc, _TCHAR* argv[])
{
//WCHAR szDataAll[64];
char szDataAll[64];
FILE* pf = _wfopen(L"d:/test.txt", L"r,ccs=utf-8");
//FILE* pf = fopen(L"d:/test.txt");
if (pf!=NULL)
{
long pos = ftell(pf); //3
ZeroMemory(szDataAll, sizeof(szDataAll));
fread(szDataAll, 2, 1, pf);
pos = ftell(pf); //9
// OutputDebugStringW(szDataAll); //中
printf(szDataAll);
ZeroMemory(szDataAll, sizeof(szDataAll));
fread(szDataAll, 2, 1, pf);
pos = ftell(pf); //11
// OutputDebugStringW(szDataAll); //文
ZeroMemory(szDataAll, sizeof(szDataAll));
fread(szDataAll, 2, 1, pf);
pos = ftell(pf); //13
// OutputDebugStringW(szDataAll); //测
ZeroMemory(szDataAll, sizeof(szDataAll));
fread(szDataAll, 2, 1, pf);
pos = ftell(pf); //15
// OutputDebugStringW(szDataAll); //试
fclose(pf);
}
else
printf(" open failed!\n");
return 0;
}
*/
#include <iostream>
#include <windows.h>
using namespace std;
const int BUF_SIZE = 1024;
int main(int argc, char *argv[])
{
HANDLE fileIn, fileOut;
char buf[BUF_SIZE];
DWORD nread,nwrote;
if ((fileIn = CreateFile(_T("d:/test.txt"), GENERIC_READ,
0, 0, OPEN_EXISTING, 0, 0)) ==
INVALID_HANDLE_VALUE)
{
cerr << "Error opening source: " <<
GetLastError() << endl;
exit(1);
}
if ((fileOut = CreateFile(_T("d:/tttt.txt"), GENERIC_WRITE,
0, 0, CREATE_NEW, 0, 0)) ==
INVALID_HANDLE_VALUE) {
cerr << "Error opening destination: " <<
GetLastError() << endl;
exit(2);
}
while (ReadFile(fileIn, buf, BUF_SIZE,
&nread, NULL) && nread > 0)
{
if ( ! WriteFile(fileOut, buf, nread,
&nwrote, NULL))
{
cerr << "Error writing" <<
GetLastError() << endl;
}
}
CloseHandle(fileIn);
CloseHandle(fileOut);
exit(0);
return 0; // never reached
}
/*
#include"stdafx.h"
#include<fstream>
#include<vector>
#include<string>
#include<iostream>
using namespace std;
int main()
{
const char filename2[]="d:/Picture_of_switch_diagnostics_stack1_prerun.txt";
ofstream o_file;// 输出流:将数据从内存输出其中ofstream是将数据输出到文件,因此对于文件来说是“写”
string out_text;
//写
o_file.open(filename2);
string filename="d:/switch_diagnostics_stack1_prerun.txt";
fstream in(filename.c_str());//打开
char str;
vector<char>ivec;
vector<char>svec;
for( ;in.get(str); )
{//放入向量
ivec.push_back(str);
}
//svec.push_back(ivec[0]);
cout<<"size of ivec: "<<ivec.size();
for(int i = 0;i<ivec.size()-1;i++)
{
//if(ivec[i].find_first_of("YRI")!=string::npos)
if(ivec[i]=='S'&& ivec[i+1]=='t'&&ivec[i+3]=='t'&&ivec[i+4]=='u'&&ivec[i+5]=='s'&& ivec[i+7]=='O')
{
svec.push_back(ivec[i]);//换行后即为第一个,放入另外一个向量
o_file<<ivec[i]<<ivec[i+1]<<"\n";
}
}
for(int i = 0;i<svec.size();i++)
{
// cout<<svec[i]<<"\n";//如果要输出数字,加上(int)在svec[i]前面
}
o_file.close();
system("pause");
}
*/
/*
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
const char filename[]="d:/switch_diagnostics_stack1_prerun.txt";
ofstream o_file;// 输出流:将数据从内存输出其中ofstream是将数据输出到文件,因此对于文件来说是“写”
ifstream i_file;//将数据输入到内存,其中ifstream是说输入的数据在文件中,因此对于文件来说是“读”
string out_text;
//写
o_file.open(filename);
for(int i =0;i<=12;i++)
{
o_file<<"第"<<i<<"行\n";//将内容写入文本
}
o_file.close();
//读
i_file.open(filename);
if(i_file.is_open())
{
while(i_file>>out_text)
{
cout << out_text << endl;
}
}
else
cout<<"打开文件:"<<filename<<"时出错!";
i_file.close();
system("PAUSE");
return 0;
}
*/
/*
#include "stdafx.h"
#include <windows.h>
//test_utf8.txt的内容是四个汉字:“中文测试”
//一共占据15个字节,分别是:
//EF BB BF E4 B8 AD E6 96 87 E6 B5 8B E8 AF 95
//其中“EF BB BF”为BOM(Byte Order Mark),之后每个汉字占3个字节
int _tmain(int argc, _TCHAR* argv[])
{
//WCHAR szDataAll[64];
char szDataAll[64];
FILE* pf = _wfopen(L"d:/test.txt", L"r,ccs=utf-8");
//FILE* pf = fopen(L"d:/test.txt");
if (pf!=NULL)
{
long pos = ftell(pf); //3
ZeroMemory(szDataAll, sizeof(szDataAll));
fread(szDataAll, 2, 1, pf);
pos = ftell(pf); //9
// OutputDebugStringW(szDataAll); //中
printf(szDataAll);
ZeroMemory(szDataAll, sizeof(szDataAll));
fread(szDataAll, 2, 1, pf);
pos = ftell(pf); //11
// OutputDebugStringW(szDataAll); //文
ZeroMemory(szDataAll, sizeof(szDataAll));
fread(szDataAll, 2, 1, pf);
pos = ftell(pf); //13
// OutputDebugStringW(szDataAll); //测
ZeroMemory(szDataAll, sizeof(szDataAll));
fread(szDataAll, 2, 1, pf);
pos = ftell(pf); //15
// OutputDebugStringW(szDataAll); //试
fclose(pf);
}
else
printf(" open failed!\n");
return 0;
}
*/