• ### Popular Now

• 13
• 18
• 19
• 27
• 10

#### Archived

This topic is now archived and is closed to further replies.

# errr help plz

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

## Recommended Posts

I''ve recently bought a book on C++ programming so that a can self teach myself.C++ Programming for the absolute beginner by Dirk Henkemans and Mark lee.Someone recommended it to me as a good place to start. The problem is that it all the code it shows is writting using a program called CodeWarrior and when I put the same code (EXACTLY the same) into my version of C++ it produces errors. I can get the program to do what it''s meant to by changing a the library from iostream to std*** and then some of the commands like "cout" to "printf" as the code in the book is using completely different libraries and commands it''s going to hard to work out the one''s for my version of C++. Anyone know where I could get the libraries from so I don''t have to keep trying each one out? OR I''ve got microsofts Visual C++ 6.0, and I don''t really want to buy another version of C++ because I can''t really afford to just yet. Any other books that are for the beginner and lead up to basic games that aren''t epensive? Thx for any help in advance

##### Share on other sites
Well with simple C++ the code should work in any compiler really. Post the code you're having trouble here and I (or someone else) will have a look at it.

[edited by - Monder on June 19, 2003 4:55:51 AM]

##### Share on other sites
I''ve been fiddling some more and I don''t think the code is wrong, it''s just when I''m creating a new project I''m creating the wrong sort.
the book says create a win32 C/C++ Application Stationary then select C++ Console App.
I ain''t got a clue which 1 to choose on mine I can choose from :-
Win32 Application
Win32 Console Application
Win32 Static Library

then

An empty Project
a simple application
a hello world app
an app that supports MFC

I''ve tried all now I think, but none add a source or header file for they add StdAfx or somet else.

the code I''ve typed is

#include <iostream>

using namespace std; //introduces namespace std
int main (void)
{
cout << "testing" ;
return 0;
}

I can get the proggy to work if I type it as

##include "stdafx.h"

int main(void)
{
printf("testing\n");
return 0;
}

##### Share on other sites
Choose console application.

##### Share on other sites
Pipo DeClown I''ve choose all of them now and yes the 1 you said is the best but I still want to know why I''m getting the
#include stdafx instead of #include iostream

I can get the program working but as I''m learning I would like to be able to get the code that is in the book to work without using different libraries etc. I''m sure I''ll have to use more Libraries later and if I can''t figure out how to get the same libraries to work with Visual C++ as the shown in the book it''s going to become quite hard to continue much further than I am so far I think.

I can''t just type in the different #include iostream as it doesn''t compile correctly can I actually add the Iostream.cpp and Iostream.h and then delete the Stdafx.cpp and StdAfx.h? if so any idea how?

as soon as I can figure this out hopefully I won''t be in here asking so many beginner questions

##### Share on other sites
What errors do you get? stdafx.h is for precompiled headers and have nothing to do with the actual language. It''s a compiler thing.

Well, tell me what errors you get and I''ll help you. If the problem is that the code compiles and links ok but when you run it nothing happens, try to add

char c;
cin >> c;

to the end of your code. (After the cout thing and before return 0). It could be as simple as that the program runs and ends you don''t see what happens before it''s over. This will fix that problem by asking for keyboard input.

- Benny -

##### Share on other sites

When I compile I get this error

--------------------Configuration: test - Win32 Debug--------------------
Compiling...
test.cpp
c:\program files\microsoft visual studio\myprojects\test\test.cpp(10) : fatal error C1010: unexpected end of file while looking for precompiled header directive
Error executing cl.exe.

test.obj - 1 error(s), 0 warning(s)

I get the same error when I add
char c;
cin >> c;
like you said

##### Share on other sites
You need to choose: Win32 Console Application. Further, make sure that you choose an empty project. That way no obscure header will be included.

That way, I can almost assure you that your code will work:
#include <iostream>using namespace std; //introduces namespace stdint main (void){cout << "testing" ;return 0;}

-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction.

##### Share on other sites
not sure if this will help but, could anyone email me a copy of iostream.cpp please?
just compiled it seperately and it has an error in it. So I think that it''s my copy which is causing the problem.

##### Share on other sites
quote:
Original post by Vivii
not sure if this will help but, could anyone email me a copy of iostream.cpp please?
just compiled it seperately and it has an error in it. So I think that it's my copy which is causing the problem.

That is higly unlikely. Unless you yourself has messed with it, it should be "flawless".

(oh, and I'm at work at the moment so I can't do that, sorry.)

-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction.

[edited by - rohde on June 19, 2003 6:13:55 AM]