发布时间: 2013-10-21 17:02:52 作者: rapoo
fstream读入文件成功与否的问题谢谢你,上半年我还是刚入门,我不知道为什么你很少关注别人的空间,然后关注了我,让我受宠若惊[解决办法]
Quote: 引用:Quote: 引用:编译成功并且运行后,为什么第一个if语句不执行?注:1、程序所在的文件夹里有名为“Saiyan_input”和"Saiyan_output"的这两个.txt文件。2、编译软件是VS 2008//#include <iostream>#include <fstream>using std::cin;using std::cout;using std::endl;using std::ifstream;using std::ofstream;using std::cerr;void keep_window_open();int main(){// construct an ifstream and bind it to the file named Saiyan_inputifstream infile("Saiyan_input.txt");// ofstream output file object to write file named Saiyan_inputofstream outfile;outfile.open("Saiyan_output.txt");// check that the open succeededif(infile){cout<<"\nGood! We can open input file: "<<"Saiyan_input"<<endl;}if(outfile){cout<<"\nPerfect! We can open output file: "<<"Saiyan_output"<<endl;}keep_window_open();}void keep_window_open(){cout << "\nPress any key to exit:"; getchar();}楼主,你这个问题其实很容易解决; if(infile) 如果打开了文件就返回1;但是没执行就是返回了0了?在这个题目上可以这样理解; 所以说,你的这个 txt文件是不存在的,如此我们可以建立这么一个文件 在 第15行加上:ofstream file("Saiyan_input.txt"); 即可。文件确实存在,这个是我检查了半个小时的结论;况且第二个if完全可以执行。
Quote: 引用:编译成功并且运行后,为什么第一个if语句不执行?注:1、程序所在的文件夹里有名为“Saiyan_input”和"Saiyan_output"的这两个.txt文件。2、编译软件是VS 2008//#include <iostream>#include <fstream>using std::cin;using std::cout;using std::endl;using std::ifstream;using std::ofstream;using std::cerr;void keep_window_open();int main(){// construct an ifstream and bind it to the file named Saiyan_inputifstream infile("Saiyan_input.txt");// ofstream output file object to write file named Saiyan_inputofstream outfile;outfile.open("Saiyan_output.txt");// check that the open succeededif(infile){cout<<"\nGood! We can open input file: "<<"Saiyan_input"<<endl;}if(outfile){cout<<"\nPerfect! We can open output file: "<<"Saiyan_output"<<endl;}keep_window_open();}void keep_window_open(){cout << "\nPress any key to exit:"; getchar();}楼主,你这个问题其实很容易解决; if(infile) 如果打开了文件就返回1;但是没执行就是返回了0了?在这个题目上可以这样理解; 所以说,你的这个 txt文件是不存在的,如此我们可以建立这么一个文件 在 第15行加上:ofstream file("Saiyan_input.txt"); 即可。
编译成功并且运行后,为什么第一个if语句不执行?注:1、程序所在的文件夹里有名为“Saiyan_input”和"Saiyan_output"的这两个.txt文件。2、编译软件是VS 2008//#include <iostream>#include <fstream>using std::cin;using std::cout;using std::endl;using std::ifstream;using std::ofstream;using std::cerr;void keep_window_open();int main(){// construct an ifstream and bind it to the file named Saiyan_inputifstream infile("Saiyan_input.txt");// ofstream output file object to write file named Saiyan_inputofstream outfile;outfile.open("Saiyan_output.txt");// check that the open succeededif(infile){cout<<"\nGood! We can open input file: "<<"Saiyan_input"<<endl;}if(outfile){cout<<"\nPerfect! We can open output file: "<<"Saiyan_output"<<endl;}keep_window_open();}void keep_window_open(){cout << "\nPress any key to exit:"; getchar();}
//#include <iostream>#include <fstream>using std::cin;using std::cout;using std::endl;using std::ifstream;using std::ofstream;using std::cerr;void keep_window_open();int main(){// construct an ifstream and bind it to the file named Saiyan_inputifstream infile("Saiyan_input.txt");// ofstream output file object to write file named Saiyan_inputofstream outfile;outfile.open("Saiyan_output.txt");// check that the open succeededif(infile){cout<<"\nGood! We can open input file: "<<"Saiyan_input"<<endl;}if(outfile){cout<<"\nPerfect! We can open output file: "<<"Saiyan_output"<<endl;}keep_window_open();}void keep_window_open(){cout << "\nPress any key to exit:"; getchar();}
getchar();}
昨天领了结婚证,该怎么解决
windows+codeblocks+gtk+ 中文乱码怎么
关于运算符重载,该怎么处理
CSDN乱码留念,该如何解决
动态分配的二维数组以矩阵方式输出
如果把一段字符串输出到光标处?解决方
list中iterator的 end( )的实现,该如何
C++字符串截取的有关问题
C/C++
居然只能输出ascii码的前128位