//
// File name : Main.cpp
//
// Code by : jiangyonghang
//
// Project name : IOStream
//
// Create datetime: 2012-10-13 08:15:18
//
// Tested or implemented header
// ...
// C system headers
// ...
// C++ system headers
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
// Headers from other projects
// ...
// Headers of current project
// ...
void FileCat(const string &infile1, const string &infile2, const string &infile3)
{
ifstream fin;
ofstream fout;
string line_of_file;
fout.open(infile3.c_str() );
fin.open(infile1.c_str() );
while (!fin.eof() && !fin.fail() )
{
getline(fin, line_of_file);
fout << line_of_file << endl;
}
fin.close();
fin.clear();
fin.open(infile2.c_str() );
while (!fin.eof() && !fin.fail() )
{
getline(fin, line_of_file);
fout << line_of_file << endl;
}
fin.close();
fin.clear();
fout.close();
fout.clear();
return;
}
void ShowFile(const string &infile)
{
ifstream fin;
string line_of_file;
fin.open(infile.c_str() );
while (!fin.eof() && !fin.fail() )
{
getline(fin, line_of_file);
transform(line_of_file.begin(), line_of_file.end(), line_of_file.begin(), toupper);
cout << line_of_file << endl;
}
fin.close();
fin.clear();
return;
}
int main()
{
string infile1("infile1.txt");
string infile2("infile2.txt");
string infile3("infile3.txt");
FileCat(infile1, infile2, infile3);
ShowFile(infile3);
return 0;
}
追问第二问怎么把小写改为大写啊,再添加什么代码啊应该
#include
#include
#include
using namespace std;
int main()
{
ifstream in_stream;
in_stream.open("E:\\infile3.dat");
if (in_stream.fail())
{
cout>x)
cout<<x<<endl;
in_stream.close();
return 0;
}
这个只是把infile3文件里的输出到屏幕上
追答不是,ShowFile的transform(line_of_file.begin(), line_of_file.end(), line_of_file.begin(), toupper);就是把小写变大写的。你可以用记事本打开infile3文件看看里面的英文字母。