[英]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) 尝试包含
iostream
并using namespace std
添加(或者using namespace std
std::string
而不是使用命名空间)
你应该在标题中使用std :: namespace前缀,比如
std::string name;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.