Linux Ubuntu C++ ++和.cp文件

Linux Ubuntu C++ ++和.cp文件,c++,linux,ubuntu,C++,Linux,Ubuntu,我有一个my.h文件: #ifndef __MY__ #define __MY__ #include <string> #include <time.h> class S { public: S(); std::string myname; }; #endif my.cpp #include "my.h"; #include<string> #include<iostream> using namespace std;

我有一个my.h文件:

#ifndef __MY__
#define __MY__

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

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

#endif
my.cpp

#include "my.h";

#include<string>
#include<iostream>

using namespace std;

S::S()
{
    // .. code
}
我想创建一个so文件。创建时没有错误。但是当我编译.h文件时,它说:string:没有这样的文件或目录。如果使用string.h而不是string,则会出现错误:应为“=”、“、”、“;”、”在我的h.h.S.S.S.S.S.S.S.S.S.S.S.S.S.S.S.S.S.S.S.S.之前。 在.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++编译器。如果不知道所使用的命令行,我就不能多说了。

编译命令行是什么?顺便说一句,在用户编写的代码中不允许创建像“我的”这样的名称。另外,最好删除MY.cppi第一行中的分号。我正在使用geany代码。我给buildIn test.cpp我调用的是.so文件:void*handle=dlopen/home/path/test.so,RTLD_现在;如果把手{coutThx代表用户答案。为什么我在cpp中收到错误:名称空间std中的.h字符串没有命名类型?我在Geany程序中工作。我刚刚从菜单中给出了构建。您的编译命令行是什么?我不知道Geany是什么。使用g++my.cpp-o my我有错误:/usr/bin/ld:/usr/lib/debug/usr/lib/crt1.o.debug\u信息:重新定位n 0具有无效的符号索引12/usr/bin/ld:/usr/lib/debug/usr/lib/crt1.o.debug_信息:重新定位1具有无效的符号索引13/usr/bin/ld:/usr/lib/debug/usr/lib/crt1.o.debug_信息:重新定位2具有无效的符号索引2