简体   繁体   English

错误C2146:语法错误:缺少';' 在标识符之前

[英]error C2146: syntax error : missing ';' before identifier

i can't get rid of these errors... i have semicolons everywhere i checked... the code is simple: the error takes me to the definition "string name" in article.h... 我无法摆脱这些错误......我检查的地方到处都是分号......代码很简单:错误将我带到了article.h中的“字符串名称”定义...

main.cpp main.cpp中

#include <iostream>
#include <fstream>
#include <vector>
#include <string>

using namespace std;

#include "article.h"

int main()
{
 string si;
 char article[128];
 vector<Article> articles;
 ifstream file;


 file.open("input.txt",ifstream::in);

 while(!file.eof())
 {
  file.getline(article,128);
  articles.push_back(Article(article));

 }

 file.close();

 while(1);
 return(1);
}

article.h: article.h:

#ifndef Article_H
#define Article_H

class Article
{
public:
 int year;
 string name;

 Article(char *i_name);
};

#endif

You should add: 你应该添加:

#include <string>

to your "article.h" header file and declare name like this: 到你的“article.h”头文件并声明如下名称

std::string name;

It seems the string type is not defined in the artivle.h file. 似乎string类型未在artivle.h文件中定义。 Try to include iostream and add using namespace std (or write std::string instead of using namespace) 尝试包含iostreamusing namespace std添加(或者using namespace std std::string而不是使用命名空间)

你应该在标题中使用std :: namespace前缀,比如

std::string name;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误C2146:语法错误:在标识符&#39;A1&#39;之前缺少&#39;,&#39; - Error C2146: syntax error : missing ',' before identifier 'A1' 错误C2146:语法错误:缺少&#39;;&#39; 在标识符之前 - Error C2146: syntax error : missing ';' before identifier 错误C2146:语法错误:缺少&#39;;&#39; 在标识符&#39;ContextRecord&#39;之前 - error C2146: syntax error : missing ';' before identifier 'ContextRecord' 模板Fn指针错误C2146:语法错误:缺少&#39;;&#39; 在标识符之前 - Template Fn Pointer error C2146: syntax error : missing ';' before identifier 错误C2146:语法错误:在按功能传递地图时,在标识符mType之前缺少',' - error C2146: syntax error : missing ',' before identifier mType when passing a map by function C ++错误1错误C2146:语法错误:缺少&#39;;&#39; 在标识符“记录”之前 - C++ Error 1 error C2146: syntax error: missing ';' before identifier 'records' 错误C2146:语法错误:缺少&#39;;&#39; 在标识符&#39;m_ball&#39;C ++之前 - error C2146: syntax error : missing ';' before identifier 'm_ball' C++, MFC VC ++错误C2146:语法错误:标识符&#39;pFirst&#39;之前缺少&#39;)&#39; - VC++ error C2146: syntax error : missing ')' before identifier 'pFirst' 错误C2146:语法错误:缺少&#39;;&#39; 在标识符“ g_App”之前 - error C2146: syntax error : missing ';' before identifier 'g_App' 错误C2146的可能原因:语法错误:缺少';'在标识符之前 - Possible reason for error C2146: syntax error : missing ';' before identifier
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM