NameSilo

Need VERY simple C++ help

Spaceship Spaceship
Watch

Mike_Wiseman

Established Member
Impact
3
Alright, this is humiliating, but it is driving me up the wall!
I decided that i would like to learn c++, so i go to a local book store and get a book called "Sam's teach yourself c++ in 21 days". So i come home, and download Microsoft Visual C++ 2005 Express Edition.

Right from the start i already have a few problems :'(
when i open visual c++ and i create a new project, I'm not sure which to choose, it gives me three options:
CLR, Win32, General

I didn't have a clue what to do, so i used the good ol' trial and error method, i found that creating a Win32 project might just be what i need to write a program but i am not positive.

But thats not all, on the VERY first page i write out exactly what I was told to write out:
#include <iostream>

int main()
{
std::cout << "Hello World!\n";
return 0;
}

So then the book tells me i need to compile it and all that junk, well not knowing how to do that once again i am stuck, so I look around the program and find the "Build" tab, i click that and then find "Build Week 1" (Week 1 being the name of my project), So i thought, hey lets try that, and so i did.

So i seen a bunch of crap come up on the screen, so im thinking to myself, alright it must of worked :hehe: But wait! In the output box on Visual C++ i see, errors? That cant be right! Heres the output message thingy:
1>------ Build started: Project: Week 1, Configuration: Debug Win32 ------
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>Week 1.cpp
1>c:\documents and settings\owner\desktop\c++ projects\week 1\week 1.cpp(8) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
1>Build log was saved at "file://c:\Documents and Settings\Owner\Desktop\C++ Projects\Week 1\Debug\BuildLog.htm"
1>Week 1 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

So i thought, alright.. I must have to add '#include "stdafx.h' on line 1, and so I did.

Thinking that would fix everything, i build again..
this cant be right! More Errors?! Am I really this big of an Idiot? I cant even get past the first page of my dam book without running into multiple errors!?

Error:
1>------ Build started: Project: Week 1, Configuration: Debug Win32 ------
1>Compiling...
1>Week 1.cpp
1>c:\documents and settings\owner\desktop\c++ projects\week 1\week 1.cpp(1) : error C2001: newline in constant
1>Build log was saved at "file://c:\Documents and Settings\Owner\Desktop\C++ Projects\Week 1\Debug\BuildLog.htm"
1>Week 1 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Please Help a huge moron out! What is going on?!
:(
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
i too struggled with C++ when i started ;)

One thing, try using Dev C++ (http://bloodshed.net/download.html) instead of Visual C++. It does the same job and doesn't give so many errors (easier to use IMO) and its free too :)

Hope that helps
 
0
•••
st0rmer said:
i too struggled with C++ when i started ;)

One thing, try using Dev C++ (http://bloodshed.net/download.html) instead of Visual C++. It does the same job and doesn't give so many errors (easier to use IMO) and its free too :)

Hope that helps

I downloaded Dev C++ and put in the exact same code:
#include <iostream>

int main()
{
std::cout << "Hello World!\n";
return 0;
}

It compiled everything without any errors, but when i tried to run it the .exe file it doesn't open at all, or maybe it just opens and closes really fast.

Maybe it would have something to do with when i started a new project it had a page with a bunch of code already on it, well i deleted all that and replaced it with just the code given above ^?
 
0
•••
Mike_Wiseman said:
I downloaded Dev C++ and put in the exact same code:


It compiled everything without any errors, but when i tried to run it the .exe file it doesn't open at all, or maybe it just opens and closes really fast.

Maybe it would have something to do with when i started a new project it had a page with a bunch of code already on it, well i deleted all that and replaced it with just the code given above ^?

Add this after the cout statement:
Code:
std::cin.get();
This causes the program to wait for an input, allowing you to read the output.
 
Last edited:
0
•••
I tried that out but I'm still having the same problem, I just don't get it, why isn't the example code straight from the book working?
 
0
•••
Mike_Wiseman said:
I tried that out but I'm still having the same problem, I just don't get it, why isn't the example code straight from the book working?

Well that should have worked. Can you paste your code again.
 
0
•••
I found the problem, i had to download some borland thing and then i copied iostream.h
and all the files included in the iostream.h file to the folder that my .exe was in.

heres the code:
#include <iostream>

int main()
{
std::cout << "Hello World!\n";
std::cin.get();
return 0;
}
 
0
•••
Mike_Wiseman said:
It compiled everything without any errors, but when i tried to run it the .exe file it doesn't open at all, or maybe it just opens and closes really fast.

It does open and close really fast as the execution has finished and ther eis no need to open it.

In visual studio you can use ctrl+f5 and it will execute the program while keeping the window open when it finishes (you press space to close it)

Mike_Wiseman said:
Maybe it would have something to do with when i started a new project it had a page with a bunch of code already on it, well i deleted all that and replaced it with just the code given above ^?

You must have used 1 of the templates rather that using the empty project option.

Mike_Wiseman said:
I found the problem, i had to download some borland thing and then i copied iostream.h
and all the files included in the iostream.h file to the folder that my .exe was in.

heres the code:


I very much doubt this was the problem. iostream is part of the c++ standard so should come with all compilers. I have Visual studio myself and had no problem with an example like you provided when I first installed it.
 
0
•••
The example should be with:

Code:
#include <iostream[b].h[/b]>
 
0
•••
Also, check out codeblocks and bloodshed dev C++ for great freeware C++ ides.

To stop the window from closing, add system("pause"); (I think...) to the end.
 
0
•••
jido said:
The example should be with:

Code:
#include <iostream[b].h[/b]>

As iostream is a part of the c++ standard there is no need for the .h in visual studio.
 
0
•••
Unstoppable Domains
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back