c++ 读写文件
2011-02-23 13:10
176 查看
ifstream inFile1;
inFile1.open("a.txt", ios_base::in);
if (!inFile1.is_open())
{
cout<<"打开导入文件文件失败,请检查是否存在导入文件"<<endl;
return false;
}
char szBuffer1[120] = "0";
string str1;
while (getline(inFile1,str1))
{
cout<<str1<<endl;
}
//cout<<inFile1.rdbuf()<<endl;
inFile1.close();
写文件例子:
string sql = "test";
ofstream outFile;
outFile.open(strExportFileName.c_str(), ios_base::app);
if (!outFile.good())
{
cout<<"打开文件失败"<<endl;
return false;
}
outFile<<sql;
outFile.close();
inFile1.open("a.txt", ios_base::in);
if (!inFile1.is_open())
{
cout<<"打开导入文件文件失败,请检查是否存在导入文件"<<endl;
return false;
}
char szBuffer1[120] = "0";
string str1;
while (getline(inFile1,str1))
{
cout<<str1<<endl;
}
//cout<<inFile1.rdbuf()<<endl;
inFile1.close();
写文件例子:
string sql = "test";
ofstream outFile;
outFile.open(strExportFileName.c_str(), ios_base::app);
if (!outFile.good())
{
cout<<"打开文件失败"<<endl;
return false;
}
outFile<<sql;
outFile.close();
相关文章推荐
- C++读写文件
- C++ 简单读写文本文件、统计文件的行数、读取文件数据到数组
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写
- C++ 简单读写文本文件、统计文件的行数、读取文件数据到数组
- C++中文件的读写(转)
- C++文件读写
- C++读写配置文件"*.ini
- C++文件读写详解(ofstream,ifstream,fstream)
- C++读写txt文件
- C++文件读写详解(ofstream,ifstream,fstream)
- C++二进制文件读写
- C++ 文件读写
- C/C++读写文件小结
- c++文件读写操作
- C++ 文件读写
- C++文件读写
- C++ 读写文件方法--fstream,ofstream,ifstream
- C++中cout控制输出格式和读写txt文件
- C/C++读写文件实例