-
IOSTREAM problem
Hi all,
I include <iostream> in my code and after compiling appears an error:
c:\program files\microsoft visual studio 8\vc\include\ostream(639) : error C2143: syntax error : missing ';' before 'template'
i work with visual studio 2005
Anyone has any idea what might be??
Thanks
-
Can you post your code? Does it happen with a small program?
Are there any #includes above <iostream>? If so the error might be in that file instead.
-
Have you disabled precompiled headers?
-
Yes, it happens also with a small program. For example:
Code:
#include <stdio.h>
#include <math.h>
#include <vector>
#include <pthread.h>
#include <iostream>
using namespace std;
int size;
vector<int> X(100);
int prime(int n)
{
bool a=true;
for(int i=2; i<n; i++)
{
if (n%i==0)
{
a=false;
break;
}
}
if (a==false)
cout << n << " is not prime";
else
cout << n << "is prime";
return 0;
}
int main()
{
int k;
cout << "give the size" << "\n";
cin >> size;
cout << "give the elements" << "\n";
for (k=0; k<size; k++)
{
cin >> X[k];
}
for(k=0; k<size; k++)
{
cout << prime(X[k]) << "\n";
}
}
Next to the cpp file appears always a box "ostream".I have looked in the code of iostream and the part between
Code:
#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE)
template class _CRTIMP2_PURE basic_ostream<char, char_traits<char> >;
template class _CRTIMP2_PURE basic_ostream<wchar_t, char_traits<wchar_t> >;
#endif
is inactive!! i don't know why.I'm quite new in programming..and another thing is that don't appear the precompiled headers!! are disabled??
-
What happens if you remove the <pthread.h> include. In fact, for this simple code, you only need <iostream> and <vector>. Does it compile if you just use those?
-
It may be refering to the header file ostream that the compiler uses to look up the
functions. Although changing this file is not recomended, one option is to run the repair feature of the software. From what I can see, there is nothing clearly wrong in the code you have given.
-
Yes, the code is correct. And with other codes happens the same..
How can i do that?? to run the repair feature??
-
If you are using VC++ 2003.net it has a repair feautr. But all of Microsofts later IDEs have it. Look in the help files for information, might be under trouble shooting. I think version 8 pf MSVC++ is 2005 edition beta free, still the same thing should apply
-
So this code gives the error?
Code:
#include <iostream>
using namespace std;
int main()
{
std::cout << "Hello.\n";
}
Has any code ever worked with this compiler for you? Did you download the platform SDK?
-
Yes.even this code..When i include <iostream> always appears the above error!! When i don't eveything works fine.
yes i have downloaded the platform SDK v2.0
-
It must be a fault with the software. I think the only thing you can do is re-install the software. Being MS, that does take a bit of time mind...
-
I just put a ; before template class _CRTIMP2_PURE basic_ostream<char, char_traits<char> >;
as it was the error and the above "hello" code works!! it was that easy?? i don't know if you ever have seen that..
-
>#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE);
Was it like the above? That line is before the line compiler was moaning at.
-
yes, the line before the one the compiler was moaning at was >#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE) without the (;)
I tried it like this and works for the "hello" code:
> ;template class _CRTIMP2_PURE basic_ostream<char, char_traits<char> >;
I don't know.It seems to me very strange