Pregunta

I am a beginner in C++, and I am here to learn.

First of all, I made some programs in Borland C++, at school, but my school doesn't have Visual C++, and I don't have anybody to teach me how to program in Visual C++.

The problem is that when I try to change the linker subsystem (project settings) to Windows (/SUBSYSTEM:WINDOWS), I get this in output window:

1>------ Build started: Project: hew, Configuration: Debug Win32 ------
1>  main.cpp
1>c:\users\mxmike\documents\visual studio 2010\projects\hew\main.cpp(1): fatal
error C1083: Cannot open include file: 'iostream.h': No such file or directory
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

My code is really simple:

#include <iostream.h>
#include <stdlib.h>

int main(int f)
{
    int i=1;
    return 1;
}

I simply don't get it. Would someone be so kind do explain to me?
Thank you for reading!

¿Fue útil?

Solución

There is no <iostream.h> header. The standard library header for I/O is <iostream>. None of the C++ standard library headers end with .h.

The headers that do exist that end with .h are from the C standard library. So, for example, <stdlib.h> is a C standard library header. The C++ standard does make these headers available, but it also provides its own alternatives with almost identical contents. Simply remove the .h and add a c to the beginning. So the C++ version of <stdlib.h> is <cstdlib>.

Whether you actually need the contents of either <stdlib.h> or <cstdlib> is a different matter. Most of the functionality has improved C++ counterparts in C++-specific headers. For example, these C headers provide malloc, but you should instead be using new-expressions in C++.

Also note that returning 1 from main is typically a sign of failure. To indicate a successful execution, do return 0; instead.

Otros consejos

There are two standard types of header files in C++. Those that derive from C, such as < stdlib.h > which in C++ should be included as < cstdlib > (take off the .h and prefix with a c) and those like < iostream > which is a C++ header file which replaces the C < stdio.h >.

What you want is:

#include <cstdio>
#include <cstdlib>

or

#include <iostream>
#include <cstdlib>

depending on which functionality/functions you call in your code (in the case you supply none so both should work).

Regards,

Jason Posit

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top