c++ - 字符串不被接受为函数的有效参数 (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
}
解决方案
您需要使用#include
而不是#define
#include <iostream>
#include <string>
using namespace std;
void somefunction(string x, int y) {
// some code here using x and y
}
推荐阅读
- java - 使用 Selenium 和 Java 将值插入输入字段
- sql - SQL - 使用联合对 2 个或更多列进行分组计数需要超过 2 秒
- java - 如何在chromecast中将可绘制图像传递给MediaMetadata
- javascript - 如何将值从组件内的常量变量传递到 React.js 中的另一个组件
- javascript - 正则表达式以 javascript 开头
- ruby-on-rails - 如何将asset_pack_path与背景图像内联css一起使用
- laravel - 检查任务调度是否适用于本地,Laravel
- automated-tests - 在赛普拉斯如何计算包含文本的元素?
- python-3.x - 模块无法识别 Python 导入的根目录
- java - 如何使用 Pulsar 作为 Log4j2 的 Appender?