This forum is in archive mode. You will not be able to post new content.

Author Topic: C++, Fresh Starter...How To Start??  (Read 6277 times)

0 Members and 2 Guests are viewing this topic.

Offline Lionofgod

  • Knight
  • **
  • Posts: 164
  • Cookies: 6
    • View Profile
C++, Fresh Starter...How To Start??
« on: 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
Code: [Select]
// 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???)

Offline Stackprotector

  • Administrator
  • Titan
  • *
  • Posts: 2515
  • Cookies: 205
    • View Profile
Re: C++, Fresh Starter...How To Start??
« Reply #1 on: 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.
~Factionwars

Offline Lionofgod

  • Knight
  • **
  • Posts: 164
  • Cookies: 6
    • View Profile
Re: C++, Fresh Starter...How To Start??
« Reply #2 on: 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.

Code: [Select]
#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, ;) )
« Last Edit: April 12, 2011, 12:24:26 AM by Lionofgod »

Offline islador

  • /dev/null
  • *
  • Posts: 6
  • Cookies: 3
    • View Profile
Re: C++, Fresh Starter...How To Start??
« Reply #3 on: 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.
Code: [Select]
using namespace std;
your code is also overly explicit, you could accomplish the same thing with
Code: [Select]
#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.
« Last Edit: April 12, 2011, 12:41:20 AM by islador »

Offline Lionofgod

  • Knight
  • **
  • Posts: 164
  • Cookies: 6
    • View Profile
Re: C++, Fresh Starter...How To Start??
« Reply #4 on: April 12, 2011, 01:01:55 AM »
Alright, so when i run it your way i get these errors
Code: [Select]
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
Code: [Select]
#include <iostream>
using namespace std;
int main()
{
cout << "hello";
return 0;
}
whats wrong?

Offline Satan911

  • VIP
  • Knight
  • *
  • Posts: 289
  • Cookies: 25
  • Retired god/admin
    • View Profile
Re: C++, Fresh Starter...How To Start??
« Reply #5 on: April 12, 2011, 01:05:30 AM »
Here's your basic C++ Hello World:
Code: [Select]
#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.
Satan911
Evilzone Network Administrator

Offline Lionofgod

  • Knight
  • **
  • Posts: 164
  • Cookies: 6
    • View Profile
Re: C++, Fresh Starter...How To Start??
« Reply #6 on: April 12, 2011, 01:18:32 AM »
TYVM
Downlaoding attahcments now :D

Offline Lionofgod

  • Knight
  • **
  • Posts: 164
  • Cookies: 6
    • View Profile
Re: C++, Fresh Starter...How To Start??
« Reply #7 on: 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

Offline Satan911

  • VIP
  • Knight
  • *
  • Posts: 289
  • Cookies: 25
  • Retired god/admin
    • View Profile
Re: C++, Fresh Starter...How To Start??
« Reply #8 on: 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
Satan911
Evilzone Network Administrator

Offline islador

  • /dev/null
  • *
  • Posts: 6
  • Cookies: 3
    • View Profile
Re: C++, Fresh Starter...How To Start??
« Reply #9 on: 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.

Offline bluechill

  • Cybermancer
  • Royal Highness
  • ****
  • Posts: 682
  • Cookies: 344
  • I am the existence in these walls
    • View Profile
Re: C++, Fresh Starter...How To Start??
« Reply #10 on: 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.
I have dreamed a dream, but now that dream has gone from me.  In its place now exists my own reality, a reality which I have created for myself by myself.

Offline Satan911

  • VIP
  • Knight
  • *
  • Posts: 289
  • Cookies: 25
  • Retired god/admin
    • View Profile
Re: C++, Fresh Starter...How To Start??
« Reply #11 on: 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.
Satan911
Evilzone Network Administrator

Offline bluechill

  • Cybermancer
  • Royal Highness
  • ****
  • Posts: 682
  • Cookies: 344
  • I am the existence in these walls
    • View Profile
Re: C++, Fresh Starter...How To Start??
« Reply #12 on: 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.
I have dreamed a dream, but now that dream has gone from me.  In its place now exists my own reality, a reality which I have created for myself by myself.

Offline Satan911

  • VIP
  • Knight
  • *
  • Posts: 289
  • Cookies: 25
  • Retired god/admin
    • View Profile
Re: C++, Fresh Starter...How To Start??
« Reply #13 on: 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.
Satan911
Evilzone Network Administrator

Offline bluechill

  • Cybermancer
  • Royal Highness
  • ****
  • Posts: 682
  • Cookies: 344
  • I am the existence in these walls
    • View Profile
Re: C++, Fresh Starter...How To Start??
« Reply #14 on: 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) ).
I have dreamed a dream, but now that dream has gone from me.  In its place now exists my own reality, a reality which I have created for myself by myself.

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.