i'm getting a problem when using cin and cout, for some odd reason it's like I'm not using a C++ compiler. I'm using Microsoft Visual C++ 6.0 and i tried using a borland compiler as well and i get the same error on several different computers. What in the world is going on?

#include <iostream>

using namespace std;

int main(void)
{
    cout << "Welcome to C++!";

return 0;
}

:evil: Frustrating I'm tired of using printf and scanf !

and i get the same error on several different computers.

Which is...?

If you want to do it right, it's <iostream>.

i just noticed i forgot the error message, thanks

c:\program files\microsoft visual studio\vc98\include\eh.h(32) : fatal error C1189: #error : "eh.h is only for C++!"

>iostream or iostream.h???
iostream. iostream.h isn't a valid C++ header anymore.

>it's like I'm not using a C++ compiler
Maybe you aren't. The file extension usually tells your compiler what language specification to use. If the file is a .c file then you're probably compiling as C, if it's a .cpp file then you're compiling as C++. Most compilers will also let you use a parameter to determine what language to compile as.

I Just noticed, the default save as is .c not .cpp that sovles the problem.. doh, funny how u can feel so stupid. I was wondering why nobody could get it to work properly. Thanks though, I'm sure I'll be having more questions. I'm an mechanical engineering major at Texas A&M and I need this class. :D I think it's fun, we get to play with robots and program them.

Just to expand on the major differences of usage:

The <iostream.h> library has been deprecated for many years now, but some C++ coders will still use it instead of <iostream> library. The .h notation of standard header files has been deprecated for about six(?) years. Of course, using deprecated libraries in new code isn’t a good idea. As for functional differences, <iostream> is templatized with I/O classes supporting narrow and wide characters. On the other hand, <iostream.h> is confined to char exclusively. It is also important to use <iostream> because the C++ standard specification of iostream’s interface and implementation has changed over time. <iostream> components are in namespace std. In contrast, <iostream.h> components are in the global scope.

Rule of thumb:

1) Never mix the two libraries due to substantial differences.

2) Use <iostream> in new code.

3) Use <iostream.h> in code not compatible with <iostream>

>The <iostream.h> library has been deprecated for many years now
If iostream.h were deprecated then all conforming compilers would be required to support it, which isn't the case. iostream.h was never a standard header, so it can't be deprecated. A correct statement would be "The <iostream.h> library has been nonstandard for many years now". The difference is becoming more important as newer compilers refuse to accept code that uses iostream.h.

Good point.

Here's an interesting (related) question:

Can the old C++ standard library co-exist with the new library in different dlls within the same process? In other words, can an .exe link two .dlls where one dll uses the old standard library and the other uses the new standard library?

Seems like it should work OK, but I've got an unexplained bug right now, and I'm wondering if that's the cause.

Thanks!

Ken

Just to expand on the major differences of usage:

The <iostream.h> library has been deprecated for many years now, but some C++ coders will still use it instead of <iostream> library. The .h notation of standard header files has been deprecated for about six(?) years. Of course, using deprecated libraries in new code isn’t a good idea. As for functional differences, <iostream> is templatized with I/O classes supporting narrow and wide characters. On the other hand, <iostream.h> is confined to char exclusively. It is also important to use <iostream> because the C++ standard specification of iostream’s interface and implementation has changed over time. <iostream> components are in namespace std. In contrast, <iostream.h> components are in the global scope.

Rule of thumb:

1) Never mix the two libraries due to substantial differences.

2) Use <iostream> in new code.

3) Use <iostream.h> in code not compatible with <iostream>

>Can the old C++ standard library co-exist with the new library in different dlls within the same process?
It depends on what names are actually linked. If you use unique names from each library (for example, cin from the old library and cout from the new library) then it's theoretically possible. However, because the new library was based off of the old one, it's unlikely that one could pull off such a feat.

i'm getting a problem when using cin and cout, for some odd reason it's like I'm not using a C++ compiler. I'm using Microsoft Visual C++ 6.0 and i tried using a borland compiler as well and i get the same error on several different computers. What in the world is going on?

#include <iostream>

using namespace std;

int main(void)
{
    cout << "Welcome to C++!";

return 0;
}

evil: Frustrating I'm tired of using printf and scanf !

*********************************************************************
mi ejemplo: by togayot
*********************************************************************

#include "stdafx.h"
#include "conio.h"
#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{
    int c,b,a;
    std::cout<<"HIRAM TOGA ESPEJO TOGAYOT\n";
    std::cout<<"CUANTOS AÑOS TIENE? : ";
    std::cin >>c;
    printf("HIRAM TOGA ESPEJO TOGAYOT\n");
    printf("vamos a sumar \n");
    printf("Valor de A\n");
    scanf("%d",&a);
    std::cout<<"Valor de B\n";
    std::cin>>b;
    c=a+b;
    printf("\ntotal de la suma: %d\n",c);
    std::cout<<"total de la suma : "<<c;
    getch();
    return 0;
}

*************************************************************
TOGAYOT
*************************************************************
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.