错误 C2061:语法错误:标识符'string'
error C2061: syntax error : identifier 'string'
这可能是
一个包含问题,我在整个代码中都收到这些错误,而不仅仅是字符串标识符,例如error C2146: syntax error : missing ';' before identifier 'getName'
和error C2146: syntax error : missing ';' before identifier 'name'
下面是一个示例类:
#include "stdafx.h"
class participant
{
public:
participant(int id, string name);
~participant(void);
int getId();
string getName();
private:
int id;
string name;
};
这是我stdafx.h
文件:
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <list>
#include "day.h"
#include "appointment.h"
#include "extendedAppointment.h"
#include "participant.h"
#include "calendar.h"
using namespace std;
#define no_such_appointment_error 20;
#define conflicting_appointments_error 21;
#define noSuchDayError 22;
#define incorrectAppointmentError 23;
所以我在没有自定义头文件的情况下编译了您的代码,它工作得很好。 基于此,我敢打赌,您在以下头文件之一中存在问题:
#include "day.h"
#include "appointment.h"
#include "extendedAppointment.h"
#include "participant.h"
#include "calendar.h"
它可以是一个宏,一个不以分号结尾的类/结构,等等。 看看那些。
最后,一些无关紧要的问题:
首先,在头文件中using
命名空间是一个糟糕的主意。任何包含标题的文件现在都有using namespace std;
(这很糟糕)。 您可能不希望在包含 stdafx.h
的每个文件中包含那么多头文件。
其次,一旦你删除了它,那么string
立即变得未定义(改用std::string)。
最后,为什么你的#define
以分号结尾? 没这个必要。
相关文章:
- C++:如何将 unix 时间的字符串转换为 *tm?(使用时间错误:"cannot convert 'String' to 'tm*' ")
- 为什么当我在 std::string 中打开文件名的 fstream 时出现"no matching function"错误?
- 错误消息:使用"string* +="后"no match for 'operator+='"
- 将图形表示为unordered_map<字符串、向量>时拓扑排序错误<string>
- OpenCV 3.4.3 中对 'cv::String::d eallocate()' 错误的未定义引用
- 错误:无法传递非平凡类型"std::string"的对象和更多错误
- 由于矢量引起的错误<string>?
- 错误:调用"es_queue::set_rpc_vector(std::vector >&, std::__cxx11::string)"没有匹配函数
- 错误:"cast"未命名类型void setCastDescription(std::string
- 错误:为"运算符 std::string {aka std::__cxx11::basic_string}"指定的返回类型<char>
- 为什么 std::atomic<std::string> 会给出微不足道的可复制错误?
- pip install uwsgi 失败,出现 /usr/local/include/string/string.h:7:10:致命错误:找不到'sstream'文件?
- 如果子类中没有构造函数方法,则错误"no matching function for call to 'LGame::LGame(String&)'"
- 使用 string::p op_back() 的编译错误
- 错误:请求从"Mstream"转换为非标量类型"std::string {aka std::basic_string<char>}"
- 编译错误"String does not name a type"
- ODBC 错误"String data, right truncation State code: 22001"与 SQL Server 数据库
- 错误"String subscript out of range"
- C2059 语法错误 'string' ?
- c++错误:' string '没有指定类型