c++文件操作绝对路径的文件打不开
#include<iostream>#include<fstream>#include<stdlib.h>usingnamespacestd;intmain(){ofst...
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
int main()
{
ofstream fout;
fout.open("C:\\Users\\123\\Desktop\\data.txt", std::ios::app|std::ios::out);
if(!fout.is_open())
{
cout << "Can not open file !" << endl;
system("pause");
return -1;
}
else
{
cout << "Successfully opened file !";
cout << endl;
//fout << "Im the data that has been ";
//fout <<"written into the file! \r\n";
fout << "Im the message that was"; fout << "appended to an existed"; fout <<"file!\r\n";
}
fout.close();
cin.get();
return 0;
}
这个绝对路径的文件老是打不开,求助,谢谢 展开
#include <fstream>
#include <stdlib.h>
using namespace std;
int main()
{
ofstream fout;
fout.open("C:\\Users\\123\\Desktop\\data.txt", std::ios::app|std::ios::out);
if(!fout.is_open())
{
cout << "Can not open file !" << endl;
system("pause");
return -1;
}
else
{
cout << "Successfully opened file !";
cout << endl;
//fout << "Im the data that has been ";
//fout <<"written into the file! \r\n";
fout << "Im the message that was"; fout << "appended to an existed"; fout <<"file!\r\n";
}
fout.close();
cin.get();
return 0;
}
这个绝对路径的文件老是打不开,求助,谢谢 展开
1个回答
推荐于2016-06-10
展开全部
刚回答了一个类似的问题,,,你参考吧
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream fin;
fin.open("d:\\yuan.txt",1);
if (!fin) cout << "failed!";
char str[1000];
while (!fin.eof())
{
fin >> str;
}
printf("%s\n", str);
fin.close();
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询