字符串不被接受为函数的有效参数(C ++)

时间:2018-06-12 19:07:33

标签: c++ string

我尝试使用以下代码,但我一直在使用C2061 关于标识符'字符串'的错误和语法错误。

编译器理解字符串,因为我可以设置一个字符串变量并要求它输出它。我使用的是Microsoft Visual Studio。

#define <iostream>
#define <string>
using namespace std;

void somefunction(string x, int y) {
    // some code here using x and y
}

1 个答案:

答案 0 :(得分:3)

您需要使用#include代替#define

#include <iostream>
#include <string>
using namespace std;

void somefunction(string x, int y) {
    // some code here using x and y
}