# C++ Problem, Finally!!

This topic is 4823 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello there, I have a problem with a small program that I am writing. When I #include <iostream> I get hundreds of errors that look a bit like these: Compiling... IntVec.cpp c:\program files\microsoft visual studio\vc98\include\xiosbase(106) : error C2146: syntax error : missing ';' before identifier 'precision' c:\program files\microsoft visual studio\vc98\include\xiosbase(106) : error C2501: 'streamsize' : missing storage-class or type specifiers c:\program files\microsoft visual studio\vc98\include\xiosbase(107) : warning C4183: 'precision': member function definition looks like a ctor, but name does not match enclosing class c:\program files\microsoft visual studio\vc98\include\xiosbase(108) : error C2146: syntax error : missing ';' before identifier 'precision' c:\program files\microsoft visual studio\vc98\include\xiosbase(108) : error C2501: 'streamsize' : missing storage-class or type specifiers Does anybody have any idea what this might be? It seems like the kind of thing that is a simple mistake but I can't work out what it is? Thanks in advance. Mark Coleman

##### Share on other sites
wel the first and fourth ones are missing ";" (obviously) dunno about the rest. Maybe you should post the related code so people can help you more.

##### Share on other sites
Can you post the code? It's kinda hard to tell what's going on from that.

##### Share on other sites
Oh man you have my condolences for your inability to post. Maybe you should try to get that problem fixed before bothering with your C++ :)

You spoke to a staff member about it?

##### Share on other sites
Man!! Every time I try to post any large amount of code I get Internal Server Error 500, Bollocks!!

Basically I have a simple app which works fine but as soon as I try to #include <iostream> I get loads of errors??

I can't post the code because it keeps crashing but there are only two files.

The top of the IntVec.cpp file looks like this:

#include <iostream>
#include "IntVec.h"

and the top of the IntVec.h file looks like this:

using namespace std;
#include <iostream>

If I remove the iostream and namespace lines to program works fine, but I need to use the iostream functions.

Any ideas?

Mark Coleman

##### Share on other sites
Never put a "using namespace std" directive in a header file. Instead of istream, use std::istream etc.

If the header file already #includes iostream, there is no need to do it in the cpp file, because it propagates.

##### Share on other sites
try to compile #include <iostream> without the small program
the errors can be in your small program and not the iostream, so if you still have these errors
then you have a faked iostream..
if they gone, then check out all your ; and }.
i had an error like this in past, i think these errors exists because missing or too many ; / }.

##### Share on other sites
Kippesoep, I think I understand, so what would I have in each file?

using namespace std; in the cpp file

and then using std::istream; in the h file??

Mark Coleman

##### Share on other sites
What about remove 'using namespace std;' and replace '#include <iostream>' with '#include <iostream.h>'?

Cheers,
ALH

##### Share on other sites
maybe you have to put using namespace std; after #include <iostream> in the header file
and in the other file just include the header file, without iostream

##### Share on other sites
Don't put "using" in a header file at all, just use "std::istream" as is. You're unlikely to need it very often anyway.

Also, the most common place for a missing semi-colon is at the end of a class declaration:

class MyClass{}; //semi-colon here!

##### Share on other sites
Ok so in the header file I put:

using std::istream and everthing should be cool.

No, include iostream and no using namespace std; right?

Mark Coleman

##### Share on other sites
VC also complains about semicolons when it misses a definition for a type:
class MyClass{};MyClassWithATypo variable; // <- syntax error missing ; before 'variable'

##### Share on other sites
Quote:
 Original post by mrmrcolemanand then using std::istream; in the h file??

not using.

#include <iostream>
//qualify it with std::
void someFunc(std::iostream& is);

putting

using namespace name;

brings all the names of functions, variables, classes etc into scope. So they could collide with some other functions, variables and classes of the same name.

putting

using name::whatever;

brings just 'whatever' from namespace 'name' into scope. So it is more restricted than putting using namespace name.

qualifying explictly

name::whatever

means nothing is brought into scope and you won't get name collisions.

You want to not have collisions, so don't put using in headers, use the explicit qualification.

There is one exception: if a derived class hides functions in the base class by overloading them, or if they are privately inherited, you can make them available by using using.

##### Share on other sites
Quote:
 Original post by ALHWhat about remove 'using namespace std;' and replace '#include ' with '#include '?Cheers,ALH

No! Bad ALH! Go to your room.

##### Share on other sites
This kind of thing has happened to me before when I was missing a semicolon somewhere else in my code, and the compiler happened to look at it just before it plunged into the iostream head file.

Make sure all your class and structure declarations have a semicolon following them. Check every line of code if your program is not tremendously large.

##### Share on other sites
I'm gonna go with semi-colon. i always get the same 105 errors when i forget that.

class foo
{

}; <- IMPORTANT!

##### Share on other sites
Ok thanks for all the feedback guys. I will go and see what I can do and hopefully all will be well.

Mark Coleman

##### Share on other sites
Quote:
 Original post by glassJAwNo! Bad ALH! Go to your room.

Why that's bad? Be more explicit please...

ALH

##### Share on other sites
The <iostream.h> header, along with lots of other headers ending in .h have been deprecated. You should be including the header files that do not have a .h at the end of them when possible. The exception to this is OS-specific header files such as <windows.h>

##### Share on other sites
That's good to know, thanks!

ALH

##### Share on other sites
Ok this must be wrong. Even when I just include iostream in the header file with no other code in the whole project I still get all the errors.

Does this mean that my iostream file is broken? I can't believe that it is so difficult to get a standard library to work!! Surely I can't have an error in my iostream? I doubt that I would have opened it up and changed anything...

Could somebody send me a 'working' version on iostream.h so that I can rule out this possibility.

Mark Coleman

[Edited by - mrmrcoleman on October 1, 2004 4:39:18 AM]

##### Share on other sites
Does look like your include files are borked.
Taking a look at XIOSBASE on line 106, it doesn't seem to recognise "streamsize" as a typedef. "streamsize" is typedeffed "int" in IOSFWD. Try copying that file from your MSVC CD to the appropriate include directory. For that matter, try simply reinstalling MSVC.

##### Share on other sites
Quote:
 Original post by AprosenfThe header, along with lots of other headers ending in .h have been deprecated.

Actually they can't be deprecated because they were never standard in the first place.

Quote:
 You should be including the header files that do not have a .h at the end of them when possible. The exception to this is OS-specific header files such as

It's not an exception. Whatever the people supplying headers choose to use as an extension, you have to use. So some libraries will have .h, others .hpp, others .hxx, etc.

The C++ standard headers don't have an extension. They acknowledge the possibility that the header doesn't necessarily exist in a file.

##### Share on other sites

This topic is 4823 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

• ### Forum Statistics

• Total Topics
628719
• Total Posts
2984384

• 25
• 11
• 10
• 15
• 14