Hi, im new to programming. I have read alot of posts on this site and am wondering if i need to learn C before i learn C++. Is learning a language before C essential? or will i just get the hang of it.
This is my second post, asking about what to learn, i am just getting confused with what and which to learn first.
I have been told to start with VB, or just start with C, and have even read that i can just learn C++ straight away. ?!

Thanks

PS. you got any good sites for free books or tutorials?

Recommended Answers

All 49 Replies

Member Avatar for iamthwee

You do not need to learn c before c++.

I found c++ so easy to learn, it should be like a walk in the park.

it is much easyer to understand c++ if you know c....

C++ isnt difficult...some people think (like me) that c++ is easyer to learn than c

K, cool. Was it the first language you learnt?

Member Avatar for iamthwee

>it is much easyer to understand c++ if you know c....

Perhaps, but some people still think c++ is just c with classes.

My advice would be to learn c++ on its own away from the distractions of c.

Sweet, thnx. You guys reply sooo fast :D:D:D

K, cool. Was it the first language you learnt?

my first language was pascal..

omg...last question ^^

ive written and comiled the "hello world" thing using Dev-C++

when i run the exe, a dos-like window pops up for half sec and dissapears...wtf? ive read and reread over what i am meant to do...?!?!?! is that whats meant to hpn?

omg...last question ^^

ive written and comiled the "hello world" thing using Dev-C++

when i run the exe, a dos-like window pops up for half sec and dissapears...wtf? ive read and reread over what i am meant to do...?!?!?! is that whats meant to hpn?

Thats because when "Hello word" is printed on a screen program ends and cmd clooses...

omg...last question ^^

ive written and comiled the "hello world" thing using Dev-C++

when i run the exe, a dos-like window pops up for half sec and dissapears...wtf? ive read and reread over what i am meant to do...?!?!?! is that whats meant to hpn?

Add

system("PAUSE");

in front of return 0;

ive written and comiled the "hello world" thing using Dev-C++

when i run the exe, a dos-like window pops up for half sec and dissapears...wtf? ive read and reread over what i am meant to do...?!?!?! is that whats meant to hpn?

The program is doing exactly what it is supposed to do, the only thing being the command window closes after displaying the output.

To make the command window stay, make the program wait for some event (like accepting a key from the user) to see the expected output.

In C do getchar( ) at the end of the program.
In C++ do cin.get( ) at the end of the program.

Any other method used, is totally platform / compiler dependent and should be best avoided.

BTW even system( "pause" ) is a non-standard method which is best avoided.

For a standard, safe way of getting the program to pause, you could use a function like this

#include <iostream>
#include <limits>

void stop()
{ 
    std::cin.ignore( std::numeric_limits<std::streamsize>::max() , '\n');
    std::cin.get();
}

int main()
{
    stop();
}

For a standard, safe way of getting the program to pause, you could use a function like this

#include <iostream>
#include <limits>

void stop()
{ 
    std::cin.ignore( std::numeric_limits<std::streamsize>::max() , '\n');
    std::cin.get();
}

int main()
{
    stop();
}

wow but this doesnt make sense

why dont you just type

#include <iostrem.h>

using namespace std;


void main()
 {
cout << "\n" ;
cin.get();
return(0);
}

@ Bench
Just to let you know that the functions cin.ignore( ) and cin.get( ) won't function as expected if the standard input stream is corrupted and its status bit not cleared. Your code is good and robust but to make it to adapt to stream corruptions, do something like:

#include <iostream>
#include <limits>

void stop( )
{
    using namespace std ;

    cin.clear( ) ;
    cin.ignore( numeric_limits<streamsize>::max(), '\n' ) ;
    cin.get( ) ;
}

@ jan1024188
There are some cases in which the simple statement getchar( ) or cin.get( ) won't work. Those being corrupted stream, or more than a single newline character hanging in the stream.

For simple cases the primitive statements work well, but if your program is a highly CUI (console user interface) dependent, you might want to have a robust function like mentioned above by me and Mr. Bench to handle fatalitites ;).

Member Avatar for iamthwee

I wouldn't put 'using namespace std' within the scope of a function.

It is better to state it at the top - just under the headers.

Member Avatar for iamthwee
#include <iostrem.h>

using namespace std;


void main()
 {
cout << "\n" ;
cin.get();
return(0);
}

We've told you time and time again, don't use void main and don't use iostream.h.

But what do you do? Dearie me.

I wouldn't put 'using namespace std' within the scope of a function.

It is better to state it at the top - just under the headers.

Declarations are best made in the proximity where they are required to be used. Limiting the scope of the namespace declaration namespace collisions can be avoided.

Programs should be made avail of only that much functionality which concerns them hence declaring the namespace in the function was for the best.

Member Avatar for iamthwee

Nope. In that case you should have just done:

std::cin.clear( ) ;
    std::cin.ignore( numeric_limits<streamsize>::max(), '\n' ) ;
    std::cin.get( ) ;

The using namespace declaration is normally when people want to avoid using std:: prefixes altogether.

Oh and even your example has its shortcomings just like Bench's. See if you can guess why.

Nope. In that case you should have just done:

std::cin.clear( ) ;
    std::cin.ignore( numeric_limits<streamsize>::max(), '\n' ) ;
    std::cin.get( ) ;

Usage of namespace declarations or prefixing them is a matter of personal style. BTW the way I have done, has been reflected in many good boooks (C++ programming language) so its actually not a bad thing as such, just difference of style.

The using namespace declaration is normally when people want to avoid using std:: prefixes altogether.

Incorrect. Not "altogether", for a specific block of code would be more like it. And when you delare it at the top, it applies to the whole source file.

Oh and even your example has its shortcomings just like Bench's. See if you can guess why.

[sarcastic]Oh, wow, I would love to hear them and if possible a good solution too please...;)[/sarcatic]
:D

Member Avatar for iamthwee

>BTW the way I have done, has been reflected in many good boooks (C++ programming language)

I doubt it, it might be just a style issue, but I ain't never seen it like that.

>Oh, wow, I would love to hear them and if possible a good solution too please...

Where's the fun in that. Guess

I doubt it, it might be just a style issue, but I ain't never seen it like that.

How can you doubt it when you haven't seen the book while I have ? ;)

Where's the fun in that. Guess

Good luck with your fictious shortcomings. Maybe we would joke at another time...

Yup, i forgot to clear the state earlier..

The only other alternative to cin.ignore etc.. would be

std::cin.clear();
std::cin.sync();
std::cin.get();

Lol, ive quit learning C++ because i heard it as too hard to learn as a first language. Instead i am learning Python :D jan1024188 gave me a great book on it :D thnx

Yup, i forgot to clear the state earlier..

The only other alternative to cin.ignore etc.. would be

std::cin.clear();
std::cin.sync();
std::cin.get();

Just a note, cin.sync() is not considered to be very reliable for removing vagabond '\n' characters.

No wonder the poor chap through in the C++ towel.

In these languages, what does intergers mean? Just basicly, im so confused...
Also, Float?!

Lol, ive quit learning C++ because i heard it as too hard to learn as a first language. Instead i am learning Python :D jan1024188 gave me a great book on it :D thnx

Just as a side note, to let you know, Python, Perl etc. and all such interpreted lanaguages are developed in C / C++.

So you can very much guess the power which goes along with the name...;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.