簡體   English   中英

linux ubuntu c++.h和.cpp文件

[英]linux ubuntu c++ .h and .cpp file

我有一個 my.h 文件:

#ifndef __MY__
#define __MY__

#include <string>
#include <time.h>

class S
{
    public: S();
    std::string myname;
};

#endif

我的.cpp

#include "my.h";

#include<string>
#include<iostream>

using namespace std;

S::S()
{
    // .. code
}

我想創建一個so文件。 創建時沒有錯誤。 但是當我編譯.h文件時它說:字符串:沒有這樣的文件或目錄。 如果我 pus string.h 而不是 string 我有錯誤:在 my.h 中的 S(在 class S)之前,預期的'=',',',';','asm'。 在.cpp 文件中(如果我用string.h 更改字符串)我在編譯后出現錯誤:命名空間std 中的字符串沒有命名類型。 我哪里錯了?

嘗試這個

#ifndef MY_H
#define MY_H
#include <string>
#include <time.h>

class S
{
public: S();
std::string myname;
};

#endif



#include "my.h"
#include<string>
#include<iostream>

using namespace std;

S::S()
{
    //code
}

好吧,首先,您似乎來自 java 因為當您鍵入時:

class S
{
  public: S();
  std::string myname;
};

我猜你的意思是:

class S
{
  public:

    S();

  private:

    std::string myname;
};

.cpp文件中,您輸入了s而不是S :請注意,C++ 對於類名稱是區分大小寫的。

另外,關於您的問題,我懷疑您當前使用的是C編譯器,而不是C++編譯器。 在不知道使用的命令行的情況下,我不能說更多。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM