IOSTREAM problem

This is a discussion on IOSTREAM problem within the C++ Programming forums, part of the General Programming Boards category; 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) : ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    58

    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

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    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.

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Have you disabled precompiled headers?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    58
    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??

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    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?

  6. #6
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479
    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.
    I'm just trying to be a better person - My Name Is Earl

  7. #7
    Registered User
    Join Date
    Nov 2006
    Posts
    58
    Yes, the code is correct. And with other codes happens the same..

    How can i do that?? to run the repair feature??

  8. #8
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479
    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
    I'm just trying to be a better person - My Name Is Earl

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    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?

  10. #10
    Registered User
    Join Date
    Nov 2006
    Posts
    58
    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

  11. #11
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479
    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'm just trying to be a better person - My Name Is Earl

  12. #12
    Registered User
    Join Date
    Nov 2006
    Posts
    58
    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..

  13. #13
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479
    >#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE);

    Was it like the above? That line is before the line compiler was moaning at.
    I'm just trying to be a better person - My Name Is Earl

  14. #14
    Registered User
    Join Date
    Nov 2006
    Posts
    58
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21