fatal error C1083 Cannot open include file 'iostream.h' No such file or directory 的解決方法
VC++6.0 中的一段程式,有用到iostream.h中的標準輸入輸出流,直接用 VS2005編譯器編譯的時候報錯“Cannot open include file: 'iostream.h': No such file or directory”。
舊的原始檔如下:
#include
int main()
{
:cout < <"hello world" <
return 0;
}
一直報上面的錯誤,無法通過編譯。
原因和解決方法,如下:
#include 是VC6以前的寫法。
#include
using namespace std;
這個是標準庫的寫法。標準庫把這些個檔案都放到std這個namespace裡面了。
可以到VC/include看看和VC6.0的區別,是iostream而不是iostream.h。
注意 和 是兩個不同的東西
是STL庫
是兼容於c的庫
所有STL庫都在std::名空間下
std::cout是 裡面的物件
namespace std: 所有的C++ Standard Library Class都包含在這個叫std的name
space裡。比如 , , 等等。所以當你使用它們其中的class時
,需要加入這個語句,using namespace std; 不然編譯器報錯。
本例可用兩種方法,如下:
方法一:
#include
using spacename std;
int main()
{
cout < <"hello world" < return 0;
}
方法二:
#include
int main()
{
std::cout < <"hello world" < return 0;
}
以上兩種方法修改後的程式碼就可以在 VS2005 下編譯通過