最近在VS2012上作C++档案读取的练习, 语法方面没有问题
但就是预期的结果跑不出来, 以下是程式码:
#include"stdafx.h"
#include<iostream>
#include<fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char chtem;
fstream io("d:\\123.txt", ios::in | ios::out);
if (!io){
cout << "File open failed!\n";
}
else{
cout << "File open successfully!\n";
while (io.get(chtem)){
cout << chtem;
}
}
io.close();
system("pause");
return 0;
}
输出结果: File open failed!
作为测试的123.txt里面就只有几个英文字母而已
IDE也没有任何错误讯息, 但io的值始终等于0
明明之前用C的fopen函数都OK, 但用C++来写就有问题
有人跟我遇到同样的问题吗?