Wondering About My C++ Methods

Wondering About My C++ Methods

Post by Tsuaxis on Thu Mar 12, 2009 8:21 pm
([msg=19887]see Wondering About My C++ Methods[/msg])

So I am in a C++ class at my high school, its a career course for us. Well anyways I will cut to the chase, we have been taught a little older C++, but only like 3 or 4 years older, and i was wondering if what I am being taught is still efficient and being used today.. and if you guys dont think its right or efficient, then why? Remember this, I know older code, but I had to teach myself some system commands and 1 more thing to work in an updated compiler..

The following is an example from the new Dev-C++ :
Code: Select all
#include <iostream>
using namespace std;
int main()
{
      cout << "Hello World!\n";
      system ("PAUSE");
      return 0;
}



The following is an example from an Visual C++ 4:
Code: Select all
#include <iostream.h>
int main()
{
      cout << "Hello World!\n";
      return 0;
}


*Also, is what I am learning good enough for college, or do I have to learn the more updated on my own. Give me link to newer code if so?*
Tsuaxis
New User
New User
 
Posts: 1
Joined: Thu Mar 12, 2009 8:03 pm
Blog: View Blog (0)


Re: Wondering About My C++ Methods

Post by dwmead03 on Thu Mar 12, 2009 9:22 pm
([msg=19889]see Re: Wondering About My C++ Methods[/msg])

I don't know what you mean by newer code. I'm a computer science/computer engineering senior in college and we use DEV C++. Hello world is a good start, but if you want to prepare for college, I would try to learn more stuff than a basic cout command. If statements, for loops, and maybe even begin learning some object oriented stuff.
User avatar
dwmead03
New User
New User
 
Posts: 30
Joined: Mon Apr 14, 2008 11:34 pm
Location: KY
Blog: View Blog (0)


Re: Wondering About My C++ Methods

Post by bird7727 on Thu Mar 12, 2009 11:48 pm
([msg=19890]see Re: Wondering About My C++ Methods[/msg])

dwmead03 is right in saying you need a hell of a lot more than text output. But if you want a comparison of your code, here it is.

First, your older code lacks the system("PAUSE"); command. Second, you need to include the cout statement as a usable statement so the compiler doesn't give you an error. You need either a statement initializing the code using the standard namespace (using namespace std;) or initializing the statements individually (#using std::cout).
bird7727
New User
New User
 
Posts: 48
Joined: Sun Feb 01, 2009 12:43 am
Blog: View Blog (0)


Re: Wondering About My C++ Methods

Post by mischief on Fri Mar 13, 2009 1:39 am
([msg=19892]see Re: Wondering About My C++ Methods[/msg])

Tsuaxis, pertaining to your 'Dev-C++' example: it is very bad practice to rely on 'system()' for anything. what if there was no 'pause' program on the system, or it wasn't in the path?

if you really need something for pausing, try invesitating the istream member 'ignore', such as std::cin.ignore().

furthermore, Dev-C++ is extremely ancient. there hasn't been an update in nearly 1500 consecutive days.

pertaining to your 'Visual C++ 4' example: using a .h extension on a standard header is depreciated. you can use c headers by preprending a 'c' to the header name and dropping the .h, such as climits, cstdio, ctime. more information here -> [urlhttp://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.4]http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.4[/url]

furthermore, i suggest picking up a good book to learn C++.
The whole secret of existence is to have no fear. Never fear what will become of you, depend on no one. Only the moment you reject all help are you freed.
--Buddha
User avatar
mischief
Poster
Poster
 
Posts: 355
Joined: Wed Jan 07, 2009 4:16 pm
Blog: View Blog (0)



Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests