Hi,
I am trying to learn C++, and to a certain extent, yeah, it's going alright so far. but I keep getting problems with header files and the like, so I would be really grateful if you guys could help me out.

1) Can't: #include "stdafx.h" - fatal error:file or directory not found.
2) For some reason, I can include the <iostream> file, but not "iostream.h".
3) Array Problem -

int anArray[3];
anArray[0] = 7;

This brings up several errors as well

This is really standing in the way of me learning the language, so any help much appreciated.

1) Can't: #include "stdafx.h" - fatal error:file or directory not found.

I would recommend that you forget stdafx.h exists. It is easier in my opinion to start with an empty project and use the standard headers than to work with VC++'s precompiled headers. The other project types all start out with the precompiled headers, which is why I recommend always using an empty project. :)

2) For some reason, I can include the <iostream> file, but not "iostream.h".

The reason is iostream.h is not a standard C++ header, but iostream is. iostream.h was part of C++ before it was standardized, and the standard replaced it with the current iostream. You should be using iostream and not iostream.h in new code.

3) Array Problem -

That snippet is fine. Can you post more? The error might be coming from somewhere else.

Error Report:

1>------ Build started: Project: Test, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>c:\documents and settings\henry\my documents\visual studio 2008\projects\test\test\main.cpp(6) : error C2466: cannot allocate an array of constant size 0
1>c:\documents and settings\henry\my documents\visual studio 2008\projects\test\test\main.cpp(6) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\henry\my documents\visual studio 2008\projects\test\test\main.cpp(6) : error C2086: 'int anArray[3]' : redefinition
1> c:\documents and settings\henry\my documents\visual studio 2008\projects\test\test\main.cpp(5) : see declaration of 'anArray'
1>c:\documents and settings\henry\my documents\visual studio 2008\projects\test\test\main.cpp(6) : error C2440: 'initializing' : cannot convert from 'int' to 'int []'
1> There are no conversions to array types, although there are conversions to references or pointers to arrays
1>Build log was saved at "file://c:\Documents and Settings\henry\My Documents\Visual Studio 2008\Projects\Test\Test\Debug\BuildLog.htm"
1>Test - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Code:

#include <iostream>

using namespace std;

int anArray[3];
anArray[0] = 7;

int main()
{
	return 0;
}

Assignment statements do not work at the global scope. Put it in the main() function:

#include <iostream>

using namespace std;

int anArray[3];

int main()
{
	anArray[0] = 7;

	return 0;
}

It is also a good idea to avoid global variables, but that is a lesson for another day. :)

commented: Problem Sovled!! : ] +1

thnx much!!

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.