我有一个my.h文件:Linux操作系统Ubuntu C++的.h和.cpp文件
#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
}
我想创建一个这样的文件。创建它时没有错误。但是,当我编译.h文件它说:字符串:没有这样的文件或目录。如果我pus string.h而不是字符串,我在my.h中的S(在类S)之前有错误:expected'=',',',';','asm'。 在.cpp文件(如果我改变字符串string.h)我有我编译后错误:名称空间中的字符串std不会命名一个类型。我错在哪里?
你的编译命令行是什么?顺便说一句,'__MY__'这样的名称不允许以用户编写的代码创建。 – 2011-04-28 08:37:30
此外,它会更好地删除分号在my.cpp的第一行 – beduin 2011-04-28 08:38:49
...你正在编译.h? – 2011-04-28 08:42:19