Error C2146: syntax error: missing ';' before identifier

I canโ€™t get rid of these errors ... I have a semicolon that I checked ... the code is simple: the error leads me to the definition of "string name" in the .h article ...

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:

 #ifndef Article_H #define Article_H class Article { public: int year; string name; Article(char *i_name); }; #endif 
+7
c ++
source share
3 answers

You must add:

 #include <string> 

into the header file "article.h" and declare the name as follows:

 std::string name; 
+12
source share

It seems that the type string not defined in the artivle.h file. Try turning on iostream and add using namespace std (or write std::string instead of using namespace)

+3
source share

You should use the std :: namespace prefix in the header, e.g.

 std::string name; 
+3
source share

All Articles