Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

missing ';' before 'using'

Tags:

c++

I'm getting this compilation error with the following code:

error C2143: syntax error : missing ';' before 'using'

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include "s.h"

using namespace std;

How is this possible? How can it be fixed?

like image 326
rach Avatar asked May 10 '11 15:05

rach


3 Answers

"s.h" might contain a class declaration that wasn't terminated with a ;

When you include a header, the C preprocessor puts substitutes header's contents in in-line, so if you look at s.h you will probably find something unterminated by ;

like image 122
逆さま Avatar answered Sep 19 '22 11:09

逆さま


The error is in your s.h. In C++, #include is only a text insertion mechanism, so if the end of a header file contains an error, you might get the error in a file that #includes the faulty file.

like image 45
Marc Mutz - mmutz Avatar answered Sep 21 '22 11:09

Marc Mutz - mmutz


It could also be that the s.h isn't a C++ header but a C header which is not declared extern C try to replace your

#include "s.h"

with

#ifdef __cplusplus
extern "C"
{
#endif
#include "s.h"
#ifdef __cplusplus
}
#endif

you could also fix this in the header file itself.

like image 33
DipSwitch Avatar answered Sep 22 '22 11:09

DipSwitch