首页 > 解决方案 > 字符串不被接受为函数的有效参数 (C++)

问题描述

我正在尝试使用以下代码,但我不断收到 C2061 错误和有关标识符“字符串”的语法错误。

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

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

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

标签: c++string

解决方案


您需要使用#include而不是#define

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

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

推荐阅读