我只有一个头文件和一个.cpp文件我只是将值传递给函数但是它给了我一个错误
的main.c
#include "me.h"
#include <iostream>
#include <sstream>
#include <string.h>
using namespace std;
int main()
{
me("http");
}
me.h
#ifndef ME_H_
#define ME_H_
#include <string.h>
class me {
public:
me(std::string u);
virtual ~me();
};
#endif /* ME_H_ */
me.cpp
#include "me.h"
#include <iostream>
#include <string.h>
using namespace std;
me::me(std::string u) {
// TODO Auto-generated constructor stub
cout << "help";
}
me::~me() {
// TODO Auto-generated destructor stub
}
我收到错误
In file included from ../src/me.cpp:8:
../src/me.h:13: error: expected ‘)’ before ‘u’
../src/me.cpp:12: error: prototype for ‘me::me(std::string)’ does not match any in class ‘me’
../src/me.h:11: error: candidates are: me::me(const me&)
../src/me.h:11: error: me::me()
make: *** [src/me.o] Error 1
答案 0 :(得分:21)
#include <string>
代替#include <string.h>
string.h是C字符串标题,在C ++中可以<cstring>
<string>
是定义std::string
答案 1 :(得分:3)
您希望#include <string>
代替#include <string.h>