我使用兩個文件在C++中編寫程序。命名空間中的「字符串不是類型」
main.cpp
#include "var.hpp"
#include <iostream>
using namespace std;
using namespace YU;
int main()
{
string god = "THL";
age = 10;
cout << age << endl;
cout << god << endl;
return 0;
}
var.hpp
#ifndef __VAR_H__
#define __VAR_H__
#include <string>
namespace YU
{
int age;
string name;
}
#endif
當我compilered它,It'get錯誤。
錯誤的信息來源是:
In file included from main.cpp:1:0:
var.hpp:9:5: Error: ‘string’ is not a type name
我不知道爲什麼,我只好include <string>
頭文件,但它仍然這麼想的工作。
我寫這段代碼只是爲了練習,而不是爲了工作。
謝謝!
+1我太慢了。 – chris 2012-04-21 04:13:43