EvilZone

Programming and Scripting => C - C++ => : Lionofgod April 11, 2011, 11:53:42 PM

: C++, Fresh Starter...How To Start??
: Lionofgod April 11, 2011, 11:53:42 PM
Hey,
 Sooo
Their was an "awesome" book posted in the ebooks section called
C++ Primer Plus 5h edition by Stephen Prata
I figured that i might as well give C++ a go!
Downloaded Microsoft Visual Studio (Ultimate) ; )
Copied Pasted the first source code into the compiler
Tried to build it
FAIL
:
// myfirst.cpp--displays a message
#include <iostream> // a PREPROCESSOR directive
int main() // function header
{ // start of function body
using namespace std; // make definitions visible
cout << “Come up and C++ me some time.”; // message
cout << endl; // start a new line
cout << “You won’t regret it!” << endl; // more output
return 0; // terminate main()
} // end of function body
What did i do wrong, how should this look?
I
Is this book outdated, will i run into a lot of problems because its too old?
(Was published in 2005)
If so should i switch over to another book (Which one???)
: Re: C++, Fresh Starter...How To Start??
: Stackprotector April 12, 2011, 12:16:48 AM
Welcome to evilzone btw.
Tough i will prefer not using visual studio related to c++ (my opinion, do what you like).
Maybe try some other programs like dev-c++, where its more about the coding than a user friendly-stunning graphics- and a form designer.

As well in the beginning you will have allot more pro's with just a clean and tiny app.
: Re: C++, Fresh Starter...How To Start??
: Lionofgod April 12, 2011, 12:23:24 AM
Okay
Im too lazy to download another Environemnt thingy
(Visual Studio was 2 gigs and im almost over my bandwith limit :( )
But i tried making a simpler app.

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

int main()
//int _tmain(int argc, _TCHAR* argv[]) 
{
cout << "hello";
return 0;
}
Now i only have one error
Error: Identifier "cout" is undefined
???wtf???
EDIT
(Btw TY, i was on before the new look came, ;) )
: Re: C++, Fresh Starter...How To Start??
: islador April 12, 2011, 12:36:50 AM
your missing namespace standard. To implement it, add a line immediately under your #includes with the text "using namespace std;" This will allow you to use many of the common expressions like cout and cin.
:
using namespace std;
your code is also overly explicit, you could accomplish the same thing with
:
#include <iostream> // this calls for the input output stream
using namespace std;
int main(){
cout << "Hello world, please kill me before my programmer makes me his slave!"
return 0;
}
you don't need any args in int main() in almost every case, no need to fuck with it.
: Re: C++, Fresh Starter...How To Start??
: Lionofgod April 12, 2011, 01:01:55 AM
Alright, so when i run it your way i get these errors
:
1>InitializeBuildStatus:
1>  Touching "Debug\Test.unsuccessfulbuild".
1>ClCompile:
1>  stdafx.cpp
1>  Test.cpp
1>c:\users\aswad\documents\visual studio 2010\projects\test\test\test.cpp(5): warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1>          Add directive to 'StdAfx.h' or rebuild precompiled header
1>c:\users\aswad\documents\visual studio 2010\projects\test\test\test.cpp(13): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.31
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
the code im running for that is
:
#include <iostream>
using namespace std;
int main()
{
cout << "hello";
return 0;
}
whats wrong?
: Re: C++, Fresh Starter...How To Start??
: Satan911 April 12, 2011, 01:05:30 AM
Here's your basic C++ Hello World:
:
#include <iostream>

using namespace std;

int main ()
{
    cout << "Hello World" << endl;

    return 0;
}

It'll work just fine in VS Ultimate.

Important note: If you copy / paste example for C++ Primer Plus some chars are not good. Like the " (good) are ” (not good).

I attached a file containing all the example from the book with proper char, syntax, indent, etc.
And I also attached answers to some of the problems (There are problems at the end of each chapter). It'll help you a lot.
: Re: C++, Fresh Starter...How To Start??
: Lionofgod April 12, 2011, 01:18:32 AM
TYVM
Downlaoding attahcments now :D
: Re: C++, Fresh Starter...How To Start??
: Lionofgod April 12, 2011, 01:29:26 AM
Sorry for the double post
But
i tried your code
nothign will work unless i have
#include "stdafx.h"
at the top of the code
: Re: C++, Fresh Starter...How To Start??
: Satan911 April 12, 2011, 02:10:11 AM
Ah perhaps you didn't create the project properly.

New Project -> Win32 Console Application -> Check "Empty Project" -> Finish
: Re: C++, Fresh Starter...How To Start??
: islador April 12, 2011, 03:02:53 AM
Satan911 beat me to it. Once you've got a project setup properly, right click the "source files" folder on the right and hit add then new item, be sure to select c++ file, just so we're working on the same config in VS10. Damned VS10 does some hacky shit, so definitely important.
: Re: C++, Fresh Starter...How To Start??
: bluechill April 12, 2011, 04:07:08 AM
This is why its better to use something like codeblocks (Or Xcode in my case) :P.  Although I do use VS Ultimate occasionally, personally, it can be a little odd in how it handles and does things considering I have a unix background.
: Re: C++, Fresh Starter...How To Start??
: Satan911 April 12, 2011, 04:39:01 AM
I used to hate Visual Studio when I started C++ and switched to Codeblocks (that's still what I use on linux). But for school project we need to use VS and I learned to love it. It's really powerful and has some nice features Codeblock doesn't (Mainly CTRL + Space for auto-complete and some other stuff). I'm not a fan of Microsoft but I'm starting to see why VS is widely used.
: Re: C++, Fresh Starter...How To Start??
: bluechill April 12, 2011, 03:08:30 PM
I used to hate Visual Studio when I started C++ and switched to Codeblocks (that's still what I use on linux). But for school project we need to use VS and I learned to love it. It's really powerful and has some nice features Codeblock doesn't (Mainly CTRL + Space for auto-complete and some other stuff). I'm not a fan of Microsoft but I'm starting to see why VS is widely used.

Well I use Xcode 4 which can now compete with those features to a certain extent.  Personally, since I'm on a mac, I use Xcode although I hate apple making you pay for xcode 4 but thats why there is bittorrent.
: Re: C++, Fresh Starter...How To Start??
: Satan911 April 12, 2011, 05:04:42 PM
Yea Xcode looks great. I haven't really used it but I'm working on a project with someone else and he's coding on Xcode and sometime I use his computer and it looks really complete.
: Re: C++, Fresh Starter...How To Start??
: bluechill April 13, 2011, 02:47:57 AM
Yea Xcode looks great. I haven't really used it but I'm working on a project with someone else and he's coding on Xcode and sometime I use his computer and it looks really complete.

Xcode 4 is.  3 didn't have good autocompletion or anything but Xcode 4 finally does and is really nice.  Although, there are some annoying features but there are some which not even VS has, local git repository for each project for example and it automatically manages them and updates them.  And even has support for remote repositories.  But an annoying features is defaulting to llvm compiler 2.0 which has weird error generation.  However, a nice feature is the static analyzer.  So there are some ups and downs.  It is also easy to use once you read the first few pages of documentation (to quote arstechnica, RTFM (Read The Fucking Manual) ).
: Re: C++, Fresh Starter...How To Start??
: Xires April 15, 2011, 06:16:54 PM
Advice for fresh starter...learn C first.
Next little bit..get a decent IDE that's not going to cripple you and your code: Code::Blocks (http://www.codeblocks.org/)