[問題] linux complier c++ string
今天我嘗試在linux上編譯自己寫的一小段程式碼
結果編譯一直錯誤並且顯示"錯誤:「string」 沒有命名一個類型"
我查了google以後 他說可能是沒有include string.h這個標頭
於是我又去修改我的程式碼並且加入string.h這個標頭檔
但是還是一直無法使用....不知道到底是哪裡有寫錯....
還請版友幫忙糾正一下 謝謝
//A.cpp 這是一個測試用的class
#include <iostream>
#include <string>
#include "A.h"
using namespace std;
A::A()
{
cout<<"call constructor"<<endl;
a="aa";
}
//main.cpp 這是主要的程式碼片段
#include <iostream>
#include <string>
#include "A.h"
using namespace std;
int main()
{
A b;
return 0;
}
//A.h 測試用class的定義
#ifndef A_H
#define A_H
class A
{
public:
string str;
A();
};
#endif
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.195.217.195
※ b60413:轉錄至看板 Linux 03/26 15:46
推
03/26 15:54, , 1F
03/26 15:54, 1F
→
03/26 15:57, , 2F
03/26 15:57, 2F
推
03/26 16:10, , 3F
03/26 16:10, 3F
修文補上A.h
※ 編輯: b60413 來自: 123.195.217.195 (03/26 16:19)
→
03/26 16:40, , 4F
03/26 16:40, 4F
→
03/26 16:47, , 5F
03/26 16:47, 5F
→
03/26 16:47, , 6F
03/26 16:47, 6F
→
03/26 16:47, , 7F
03/26 16:47, 7F
→
03/26 16:48, , 8F
03/26 16:48, 8F
→
03/26 17:00, , 9F
03/26 17:00, 9F
→
03/26 17:15, , 10F
03/26 17:15, 10F
推
03/26 17:17, , 11F
03/26 17:17, 11F
推
03/26 18:08, , 12F
03/26 18:08, 12F
→
03/26 18:08, , 13F
03/26 18:08, 13F