error C2143: syntax error : missing ';' before 'namespace'
-
Wednesday, October 14, 2009 9:30 PM
Ok.. so I decide to start learning some inteligence <c++> and start in Visual C++ latest down load, get the turorials suggested which are great and get cracking at it.
/* FeetToMeters.cpp : Demonstrates a conversion program that uses a decimal point value */ #include "stdafx.h" #include <iostream> using namespace std; int main() { // Define the variables double f; // holds the value of "feet" double m; // holds the value of "meters" // Get the lenfth to calculate from the user cout << "Enter The value in Feet: "; cin >> f; cout << "\n"; // new line // Convert to meters using the formula m = f / 3.28; // This is the formula cout << f << " Feet Is Equal To " << m << " meters\n"; return 0; }
After the fourth lesson I get the following build error
c:\program files\microsoft visual studio 9.0\vc\include\istream(13) : error C2143: syntax error : missing ';' before 'namespace'
the only difference with the various lesson projects I have been working on is the actual code
int main()
{
code.....
code...
return 0
}
after typing the attached code I am unable to build all previous project lessons, I did the whole reboot thing and still the same problem?
All Replies
-
Wednesday, October 14, 2009 10:34 PMGo to the directory indicated in the error message:
c:\program files\microsoft visual studio 9.0\vc\include\
Open the file istream with an editor or viewer. (Notepad will do.)
Copy and paste the first 20 lines of that file into a post here.
- Wayne -
Wednesday, October 14, 2009 11:11 PM
I suspect that you have a missing semi-colon or closing brace in your stdafx.h header file. You should begin your search there.
Best Wishes,
-David Delaune -
Wednesday, October 14, 2009 11:23 PMQuote>I suspect that you have a missing semi-colon or closing brace in your stdafx.h header file
Note that the OP said:
Quote>after typing the attached code I am unable to build all previous project lessons
I take this to mean that projects which previously built cleanly will no longer do so.
Since each project should have it's own stdafx.h it seems unlikely that this is the
source of the problem.
Note that the error message says:
missing ';' before 'namespace'
and points to line 13 of the header istream.
I see no word "namespace" anywhere in the istream header of my installation.
- Wayne -
Wednesday, October 14, 2009 11:52 PM
Note that the error message says:
missing ';' before 'namespace'
and points to line 13 of the header istream.
I see no word "namespace" anywhere in the istream header of my installation.
- WayneHi Wayne,
Check your definition of _STD_BEGIN.
Best Wishes,
-David Delaune -
Thursday, October 15, 2009 12:00 AMQuote>Check your definition of _STD_BEGIN.
Will no-one rid me of these meddlesome macros?
Good catch. Thanks.
- Wayne -
Thursday, October 15, 2009 5:45 AM
Hi Wayne
That is correct regarding all the previous compiled projects, I have attached the requested code
// istream standard header #pragma once #ifndef _ISTREAM_ #define _ISTREAM_ #ifndef RC_INVOKED #include <ostream> #ifdef _MSC_VER #pragma pack(push,_CRT_PACKING) #pragma warning(push,3) #endif /* _MSC_VER */ _STD_BEGIN; // TEMPLATE CLASS basic_istream template<class _Elem, class _Traits> class basic_istream : virtual public basic_ios<_Elem, _Traits> { // control extractions from a stream buffer public: typedef basic_istream<_Elem, _Traits> _Myt; typedef basic_ios<_Elem, _Traits> _Myios; typedef basic_streambuf<_Elem, _Traits> _Mysb; typedef istreambuf_iterator<_Elem, _Traits> _Iter; typedef ctype<_Elem> _Ctype; typedef num_get<_Elem, _Iter> _Nget; -
Thursday, October 15, 2009 7:07 AMThat looks kosher, so the problem is probably earlier.
Looking at the include chain from iostream, it pulls in istream which pulls in ostream
which pulls in ios which pulls in xlocnum which pulls in climits, etc. etc. Before that,
stdafx.h pulls in targetver.h etc. etc. All of the above are pulled in (at least a few
dozen files) before we reach line 13 of istream where the error occurs.
First, go to the Project Properties and under
Configuration Properties=>C/C++=>Advanced
set the field "Show Includes" to "Yes" then click on "Apply/OK".
Rebuild.
Go to the output window, select all of the lines, copy to Windows clipboard
and paste here in a message.
Second, answer these questions:
(1) Did you give each project its own name, or did you use the same name for each
project?
(2) Click on the Build menu, then click on "Clean Solution". Rebuild. Does the
problem persist?
(3) If the problem is still there, go to the Project Properties and under
Configuration Properties=>C/C++=>Precompiled Headers
set "Create/Use Precompiled Header" to "Not Using Precompiled Headers"
then click on "Apply/OK". Rebuild. Does the problem persist?
- Wayne -
Thursday, October 15, 2009 2:54 PM
Hi Wayne
Ok, I have carried out each instruction as mentioned and the result is still the same. As for each project, they were all started as new projects and allocated a name and stored in the folder C:/ my docs/.../ Chapter 1. Could the problem be because I have more than one project in the same folder.
I have attached the requested info:
------ Build started: Project: FeetToMeters, Configuration: Debug Win32 ------ Compiling... stdafx.cpp Compiling... FeetToMeters.cpp Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\iostream Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\ostream Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\ios Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\xlocnum Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\climits Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\yvals.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtdefs.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\use_ansi.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\limits.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtdefs.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\cstdio Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\cstdlib Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\stdlib.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtdefs.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\streambuf Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\xiosbase Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\xlocale Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\cstring Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\string.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtdefs.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\stdexcept Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\exception Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\xstddef Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\cstddef Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\stddef.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtdefs.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\eh.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtdefs.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\malloc.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtdefs.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\xstring Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\xmemory Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\new Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\xutility Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\iosfwd Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\cwchar Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtdbg.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtdefs.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\typeinfo Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\xdebug Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\xlocinfo Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\xlocinfo.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\ctype.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtdefs.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\locale.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtdefs.h Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\share.h c:\program files\microsoft visual studio 9.0\vc\include\istream(13) : error C2143: syntax error : missing ';' before 'namespace' c:\program files\microsoft visual studio 9.0\vc\include\ostream(50) : fatal error C1903: unable to recover from previous error(s); stopping compilation c:\program files\microsoft visual studio 9.0\vc\include\ostream(642) : see reference to class template instantiation 'std::basic_ostream<_Elem,_Traits>' being compiled with [ _Elem=char, _Traits=std::char_traits<char> ] c:\program files\microsoft visual studio 9.0\vc\include\istream(13) : see reference to class template instantiation 'std::basic_ostream<_Elem,_Traits>' being compiled Build log was saved at "file://c:\Documents and Settings\Reaper\My Documents\Visual Studio 2008\Projects\Chapter 1\FeetToMeters\FeetToMeters\Debug\BuildLog.htm" FeetToMeters - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== -
Wednesday, October 21, 2009 4:18 AMDid you resolve this problem yet?
The list of headers looks suspicious - I see no reference to stdafx.h which
should have been the first header listed. It should have been followed by the
headers which it pulls in. Did you turn off precompiled headers as I suggested?
- Wayne
-
Monday, October 03, 2011 3:31 PM
Hi Dude,
I have faced the same problem. The resolution to this problem you need to check the all header files include included in your project.
In stdafx.h file may contains some of your own header files. That header files has errors i.e. struct defined in those files may missing the semicolon at the end.
I think this will help you.
Ayyavu -
Wednesday, October 05, 2011 12:49 PM
Hello,
reinstall your Visual Studio application. Safer and faster.
do not waste your time to look in headers. you are in the learning curve...
Christophe Pichaud

