PDA

View Full Version : Help with C++


Space05us
June 8, 2007, 22:35
So, I bought a book called "Teach Yourself C++ in 21 Days" because I wanted to see if I like coding. I created the little "Hello World" program but when I run it it runs and closes before I get the chance to sit and bask in the glory of my work.

Is there anything I can change so it stays open while I pat myself on the back?


I'm using Dev-C++ as the compiler if it matters.

Kuciwalker
June 8, 2007, 22:54
I think I actually had that book a long long time ago. IIRC it tells you to put a getch(); at the end of the program, to make it pause for input (and then quit).

alva
June 9, 2007, 00:06
Buy a new book called: "teach yourself C#"* instead and download Visual Studio Express (free and legal). You'll thank me for it.



* not a real title, just a reference for a (better**) language.

** don't even think about starting a debate, you know what I mean.

aneeshm
June 9, 2007, 00:21
Originally posted by Kuciwalker
I think I actually had that book a long long time ago. IIRC it tells you to put a getch(); at the end of the program, to make it pause for input (and then quit).

:shame:

snoopy369
June 9, 2007, 00:32
Most c++ compilers that compile to a console-type app have an option for whether or not to automatically close the window when it finishes running.

Anyway, to echo alva, don't learn c++ unless you're into heavy backend coding, or want to mod Civ4's dlls. Learn Visual something... C#, C++, whatever, but it needs to have "Visual" at the front end. Visual Studio Express 2005 is an amazing and free software suite that MS provides, almost making me not hate them anymore ... almost.

Whoha
June 9, 2007, 02:01
either run it from a console window(so it displays, finishes, but the text remains), or put one of the get character functions in after your print statement.

Ari Rahikkala
June 9, 2007, 06:21
Originally posted by Space05us
So, I bought a book called "Teach Yourself C++ in 21 Days" because I wanted to see if I like coding.

Learning C++ to see if you like coding is like sticking your dick in a milking machine to see if you like sex. Don't listen to snoopy369, the problem isn't the absence of "Visual" in the title, the problem is the presence of "C++" in the title. My recommendation is that you try a language that you can ask questions, i.e. one that has a REPL, such as Python, Ruby or Haskell.

cap601
June 9, 2007, 07:50
http://aditsu.freeunixhost.com/dev-cpp-faq.html#pause

Solver
June 9, 2007, 08:05
Yeah, don't start with C++ to learn programming. And don't listen to snoopy either ;). If you start by learning visual programming in Visual Basic or Visual C#, you'll have big problems switching to something else later.

You'll want/need to learn C++ at some point if you are serious about programming, but it's certainly not a language for beginners. Python is popular lately and is a great language, fairly easy, free and powerful. So that'd be my recommendation for learning programming.

And don't listen to Ari while you're at it, Haskell is not for everyone ;)

Harovan
June 9, 2007, 09:13
Snoopy's proposal Visual Studio Express 2005 is actually a very good one. It's free, it has a good IDE with integrated debugger and it doesn't come with the MFC, hence it is pretty clean of the usual "Visual" bloat. In fact, it isn't "Visual" at all. For lean console programs it's ideal.

Languages like Python, while undoubtly powerful, usually have a pretty short span of usefulness. They're like "languages of the season" and as soon as something else becomes en vogue become obsolete soon. This doesn't matter by the way - you don't "learn programming languages", you "learn programming". And if you really know one language, you usually don't have trouble to get into another.

By the way (and getting back to your initial question): In Visual C++ 2005, if you run the program out of the IDE using Ctrl-F5 (not just F5), it prompts to enter a key as soon as it terminates, without you having to do anything.

reds4ever
June 9, 2007, 09:15
Learn Smalltalk, its the language of the future!!!!!

Jon Miller
June 9, 2007, 09:18
My first (and only) comp sci class used scheme.

JM

Solver
June 9, 2007, 09:23
Snoopy's proposal Visual Studio Express 2005 is actually a very good one. It's free, it has a good IDE with integrated debugger and it doesn't come with the MFC, hence it is pretty clean of the usual "Visual" bloat. In fact, it isn't "Visual" at all. For lean console programs it's ideal.

Depends on how you use it. VS2005 is the best IDE IMO, but then care must be taken to begin with console programming and slowly go on to more advanced stuff. Visual programming is good, too, but if you start with it, you get problems with other stuff later.

Languages like Python, while undoubtly powerful, usually have a pretty short span of usefulness. They're like "languages of the season" and as soon as something else becomes en vogue become obsolete soon.

Given how much Python has been used in recent years, including uses by Google, NASA and various Linux distributions, I fully expect Python to keep growing in popularity for the next few years at least, and stay useful after that. It's rare for a language to combine ease-of-use and power like Python does.

aneeshm
June 9, 2007, 09:34
For a nice intro to programming through Scheme, you can go here (http://swiss.csail.mit.edu/classes/6.001/abelson-sussman-lectures/).

They have a complete set of videos of 20 lectures which cover the entire fundamental course.

Harovan
June 9, 2007, 09:46
Originally posted by Solver
Depends on how you use it. VS2005 is the best IDE IMO, but then care must be taken to begin with console programming and slowly go on to more advanced stuff.

Well yea, that's what learning is about. Start with the simple things and advance to the more difficult later.

Best thing is even, in Settings/C++/Language, set "Turn language extensions off" to yes. This forces you to use ANSI/ISO stuff only, i.e. commands/functions that are everywhere the same. Best for learning purposes.

Visual programming is good, too, but if you start with it, you get problems with other stuff later.

I have problems to call that "programming". It's more like "clicking stuff together". It's easy to get into it, but if someday you are confronted with another environment, you'll notice that you don't know **** about programming.

Solver
June 9, 2007, 09:58
Well yea, that's what learning is about. Start with the simple things and advance to the more difficult later.


Only problem is, visual programming may seem simpler than console programs ;). So one might be tempted to do visual stuff instead of console.

I have problems to call that "programming". It's more like "clicking stuff together". It's easy to get into it, but if someday you are confronted with another environment, you'll notice that you don't know **** about programming

I can't really agree. Yes, if all you've done is visual programming, you're in for a very hard revelation when you need to do something non-visual. But in visual programming you still got to write code. GUI is what you click together, and there's a whole host of applications where designing a form in Visual Studio in 30 minutes is preferable to spending a day coding the GUI up with some widget library.

Pekka
June 9, 2007, 10:10
I'd agree with Ari Rahikkala here. I would recommend Python.

I think the issue here is understanding the situation and that is a person who doesn't have programming experience and wants to play with it and see if there's more to it.

I think C++ is not the best possible start to do that. Of course, if you need to be a programmer, you need to know C++, but if you're still learning, it doesn't matter what the language is as long as it's generic enough to follow the simple principles and has good support.

For this, I'd recommend Python. You don't want to be struggling with syntax the first 21 days, because inexperienced people who kind of go with it alone, it's not intuitive at first. A lot of programmers, claiming to be decent and giving you a list of languages 'they know', it doesn't impress me, unless they really know what they're talking about.

Programming in general is a field where you're attacking it on all fronts at the same time, OTOH you need to learn the syntax first, or bits of it, some fundamentals of programming, but a lot of 'programmers' do not know the basics such as just really working algorithms, different data structures, the complexity and why you should not do certaing things even if 'it works' and find another way to do it.

I see a lot of code with basically horrible structures, people not really thinking enough if this certain function I want should be a class or a method or whatever.

So I'd say choose a simple and generic language to work with, because you also want to see some things you can do with it, at first the only thing you're really doing is copying the code from the book and just executing it on your own computer.

I mean a lot of people can then examine the code and understand what happens in every line, but when you're supposed to do a similar task but from your own head, nothing happens. So, a lot of programmers aren't thinking, they aren't actually planning how to solve the problem the best way first. You see elegant code ONLY when it's done properly like that, because you see how the programmer was thinking and you agree with the solution.

So I'd say just try to learn some and not get too hung up on some little things, don't try to book learn things, remember the words, it's important to understand and that can take a bit time but when you do understand it, it all falls into places, it becomes logical and easy.

Koyaanisqatsi
June 9, 2007, 10:48
Python is a weird language. It always feels too simple to me, like I'm cheating or something.

I say start with Java or C++ if you want a solid foundation. Some of these other 'easier' languages hide things from you so you never really know what's going on and therefore write code that looks like you don't know what's going on. You can easily go to another language after learning one of those, but I'm not as sure that the skills you learn for Python etc. are as portable.

Solver
June 9, 2007, 10:59
On the contrary, if you begin with an easier language, you can pick up the more difficult concepts later from learning C++. If you start with C++, there's immediately a lot you need to absorb, which might scare you off too easily.

Provost Harrison
June 9, 2007, 10:59
I think assembler would be the best place to start :D

alva
June 9, 2007, 11:01
Neither do you everything with Java as it works on the same level as C#. The question is, do you really need to until you're good enough, personally, I don't think so.

The good thing about Java or C# over say, Python, is that they are more structured and in some ways stricter (though I must add that I have very little experience with Python).

I think C++ is not the best possible start to do that. Of course, if you need to be a programmer, you need to know C++, but if you're still learning,

Why?
Name me something that needs C++ over C#, in your first 5 years of programming.

If you start by learning visual programming in Visual Basic or Visual C#, you'll have big problems switching to something else later.

Not sure if I get this.
It's great to get some practice and experience quickly while still keeping it fun. The rest comes later.

alva
June 9, 2007, 11:05
Originally posted by Solver
On the contrary, if you begin with an easier language, you can pick up the more difficult concepts later from learning C++. If you start with C++, there's immediately a lot you need to absorb, which might scare you off too easily.

True. But that's why I personally think VB.net* or C# is good way to start, C++ is a step too high and Python allows too much for picking up bad habits.


* Nope, not getting into this one either. :p ( anyway, VB.Net is much closer too C# than it is to 'old' VB.

Koyaanisqatsi
June 9, 2007, 11:08
Originally posted by Solver
On the contrary, if you begin with an easier language, you can pick up the more difficult concepts later from learning C++. If you start with C++, there's immediately a lot you need to absorb, which might scare you off too easily.
Hey, if you're not going to like it, might as well find out immediately.... ;)

I've never actually used C#, so I can't comment on that one.

aneeshm
June 9, 2007, 11:09
I don't understand the problem with starting with C++.

I started with C when I was about twelve years old. Continued with C++ as part of my school subjects for two more years. I haven't faced any problems so far.

Solver
June 9, 2007, 11:25
Name me something that needs C++ over C#, in your first 5 years of programming.

When you get a job and get assigned to maintaining a C++ program. Like it or not, the majority of software is currently written in C++ (though I expect the proportion of C# to increase a lot). If you get a job as a programmer, chances are you'll need C++.

Not sure if I get this.

Imagine someone who starts with VB. Old or .NET, doesn't matter. This someone gets used to creating interfaces by designing forms visually. Now, switching to programming in C++ with MFC, or Python, or almost anything else, they'll be confused as to how interfaces are created, not being used to the whole idea of writing code to create a GUI.

But that's why I personally think VB.net* or C# is good way to start, C++ is a step too high and Python allows too much for picking up bad habits.

I have no objections to VB.NET as a language. It's a good way to start, but C# is marginally better IMO, because few languages have a VB-like syntax. If you can read C#, you can read quite an amount of code in other languages.

I don't see how Python encourages bad habits anymore than VB could. The only bad habit I see is that Python doesn't require you to specify the type of a variable when you declare it, but that's not too bad. And Python teaches you to use proper indentation.

snoopy369
June 9, 2007, 11:48
If you're getting into programming as a career, Solver and the rest of that argument chain makes sense.

If you're just a random guy wanting to mess around with programming and make a few fun programs (again unless you want to mod Civ), go with VB.NET or one of the other Visual Studio Express languages, like I and others said above. The simple reason is that you will make more powerful programs more quickly, and thus you will probably enjoy yourself more.

You won't learn proper coding style, but frankly it is rare that a self-taught hobbyist coder learns proper coding style, C++ or VB.NET. You can always take a class to learn it later once you decide you love writing incredibly powerful programs in a few hours' work :)

Solver
June 9, 2007, 11:56
If you're a hobbyist, knowing C++ has the advantage of being able to study a lot of available code. Simply put, it's currently the most widely-used language. That already means that knowing C++ is a benefit.

But yes, if all you want is messing around now and then and aren't really serious about programming, VB.NET would probably be enough for everything you'll ever want.

Kuciwalker
June 9, 2007, 11:56
Originally posted by Solver
On the contrary, if you begin with an easier language, you can pick up the more difficult concepts later from learning C++. If you start with C++, there's immediately a lot you need to absorb, which might scare you off too easily.

Eh. I preferred learning memory management, etc. right off the bat.

Solver
June 9, 2007, 11:58
That's because you're a theoretician anyway, you're all weird that way :p

snoopy369
June 9, 2007, 12:00
Originally posted by Kuciwalker


Eh. I preferred learning memory management, etc. right off the bat.

Echoing solver... meh. Memory management is what scares off many coders. (C++ scares off a lot of coders, period, but memory management is a lot of it.)

reds4ever
June 9, 2007, 12:00
I take it people have stopped reading the OP?

Solver
June 9, 2007, 12:03
Originally posted by snoopy369


Echoing solver... meh. Memory management is what scares off many coders. (C++ scares off a lot of coders, period, but memory management is a lot of it.)

To be honest, what scares even more people is C memory management and all the pointer magic.

Seriously, there are people who enjoy learning that sort of stuff, but they're the hardcore computer scientists. Many coders don't want to deal with it, and hobbyists certainly don't. Hobbyists want a relatively simple way to make applications that do something fun/useful, not to learn the intricacies of memory management, floating point and pointer arithmetic.

alva
June 9, 2007, 12:19
Imagine someone who starts with VB. Old or .NET, doesn't matter. This someone gets used to creating interfaces by designing forms visually. Now, switching to programming in C++ with MFC, or Python, or almost anything else, they'll be confused as to how interfaces are created, not being used to the whole idea of writing code to create a GUI.

So one should stick with notepad because if you do learn Office but go to a different company which uses something else, one is ****** ?

I have no objections to VB.NET as a language. It's a good way to start, but C# is marginally better IMO, because few languages have a VB-like syntax. If you can read C#, you can read quite an amount of code in other languages.

As Sir Ralph said before - though in different wording - the syntax matters not. You switch from VB.Net to C# in a matter of days.
Once you're good at typing, you'll be good on both a Qwerty or Azerty keyboard once you adapt.

If you're a hobbyist, knowing C++ has the advantage of being able to study a lot of available code. Simply put, it's currently the most widely-used language. That already means that knowing C++ is a benefit.

How many 'hello worlds' do you need. C++ is like trying to see every nudie pic on the internet. ;)
There's more than enough on just C# to keep you going for quite awhile.
I'm not arguing that knowing (and being good!) at C++ is bad thing, just that it might be better to spent your time elsewhere...say in learning how to to code well. :p
In a few years time (when anyone starting now is good enough), C# may very well be bigger than C++.
I definitely see more job offers specifically mentioning C# than C++ btw. What is true is that if you do know C++, you might still get the job because for some reason, people think that anyone who can code in C++ must by definition be awesome (and the reverse is assumed with VB.Net).

But yes, if all you want is messing around now and then and aren't really serious about programming, VB.NET would probably be enough for everything you'll ever want.
You can do pretty much anything you want with VB.Net...even serious programming.

See, the thing is, you don't need to know how to program low level drivers to be a decent programmer making a decent living, not everyone is going to end up at the very top. A lot of decent/programmers may/will never need it and still do well.

alva
June 9, 2007, 12:21
Originally posted by Kuciwalker


Eh. I preferred learning memory management, etc. right off the bat.

That's because you are smart enough to handle it (right of the bat), most people can't. You know, normal folks. :p;)

alva
June 9, 2007, 12:22
Originally posted by reds4ever
I take it people have stopped reading the OP?

:lol::lol::lol:

Hey, he got his answer...somewhere...buried in there. :D

alva
June 9, 2007, 12:24
Seriously, there are people who enjoy learning that sort of stuff, but they're the hardcore computer scientists.

Voila...

How big a percentage of professional programmers do they make?

Ari Rahikkala
June 9, 2007, 12:26
Most of the things that I know and that are worth saying have already been said, but I'd just like to remind you of something: Space, if you find that you will want to spend the next 30 years of your life programming, you have to understand the technical background well. Koyaanisqatsi should be thwacked over the head with a Common Lisp manual for suggesting that Java and C++ will do that right.

Fortunately, you can just follow Ari's 3-step low-fat peril-avoiding (http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html) computer science self-education program to get the technical background, and get it right. It keeps you nicely insulated from all of the major developments in programming since the 70's, thus making sure that you will know how much to appreciate the niceness of the more modern languages:

1. Learn some Scheme.
2. Learn some C.
3. Follow Ari's 3-step low-fat peril-avoiding computer science self-education program.

Once you know how to apply tail-call optimisation to that program you'll be off to a good start :).

Solver
June 9, 2007, 12:28
So one should stick with notepad because if you do learn Office but go to a different company which uses something else, one is ****** ?

False analogy. It's unlikely that, when you know Office, you'll be required to move to a more complex office suite for a different task. But if all you know is graphical GUI design, you are probably going to need to move to a more advanced situation.

As Sir Ralph said before - though in different wording - the syntax matters not. You switch from VB.Net to C# in a matter of days.
Once you're good at typing, you'll be good on both a Qwerty or Azerty keyboard once you adapt.

True enough, but the difference between VB.NET and C# is superficial enough anyway. The main differences being that C# is more popular and has a syntax more similar to other languages - which is why I think it's preferable, but as I said, marginally so.

There's more than enough on just C# to keep you going for quite awhile.

Sure. But knowing C++ would let you study some of the most popular open-source software out there. Such as much of Gnome or KDE. But yes, there's enough in C# as well.

In a few years time (when anyone starting now is good enough), C# may very well be bigger than C++.

I hope so. I feel the interactions of C++ with modern platforms like .NET are too contrived and that C# is generally superior. So I'll only be happy if C# overtakes C++ in popularity.

You can do pretty much anything you want with VB.Net...even serious programming.

I didn't say VB.NET doesn't allow serious programming, I said if you're serious about programming VB.NET isn't enough. That's not because of VB itself but rather because anyone who is serious in programming needs to be proficient in several languages and to be able to pick new ones with ease generally. I'm not one of the VB haters :)

Kuciwalker
June 9, 2007, 12:31
Originally posted by snoopy369
Echoing solver... meh. Memory management is what scares off many coders. (C++ scares off a lot of coders, period, but memory management is a lot of it.)

malloc and pointers are the fun part :shame:

snoopy369
June 9, 2007, 12:34
Where did Space suggest he wanted to be a professional programmer?

Just curious ;)

Solver
June 9, 2007, 12:40
It's our duty to convert people ;)

Pekka
June 9, 2007, 12:45
Some good advices here, and I'd say about 50% are extremely bad. So how can a person now know what who to believe?

Well, some of us actually have serious professional talent, have to work with not only code but also evaluating it, and some of us are script writing 'coderz'. These people usually will start their sentences as "I found it...". That is, they have no experience other than their own, which in most cases in here is very limited as well.

I'm not saying people are stupid here, I'm saying 50% of advices in here are really shitty. This is not about you, this is about a guy who is wanting to learn some programming from scratch and maybe find out if he can enjoy this. So a very nice way for many of you is to make sure this spark is killed with *YEAAAH!11 DUDE YOU HAVE TO like install this new Linux first over the net, soem of the older Debians because this way your code is really like robust and stuff. Also, you should start from x and y because z is too easy!!".

What is this? I mean, to me this sounds like insecurity, and a need to do some virtual circle jerk about stuff people supposedly know. Who cares? NOrmally I wouldn't say a thing, normally I'm the one shouting I'M THE BEEEST, but it's a case of someone wanting to learn something new, and just unreal advices coming left and right. You want to keep it simple at first for most, OK? Most _skilled_ people would know this, because things are simple to them, so they understand and appreciate the situation.

So yeah, rock on ****ers.

Harovan
June 9, 2007, 12:52
Originally posted by Solver
Well yea, that's what learning is about. Start with the simple things and advance to the more difficult later.


Only problem is, visual programming may seem simpler than console programs ;). So one might be tempted to do visual stuff instead of console.

That's why I recommended VC++ 2005 Express for learning purposes. It comes without MFC and is not visual at all.

snoopy369
June 9, 2007, 12:55
Originally posted by Solver
It's our duty to convert people ;)

You mean increase competition for your potential jobs? :shame:

Harovan
June 9, 2007, 12:57
As for the C# vs C++ discussion... They have both their purpose.

C# is a great thing to make the GUI of an application. Sure you can do it with C++ and a class library (MFC, SmartWin and alike or an equivalent for UN*X), but using C# or Java is much less painful.

C++ is good for the core of a computation-heavy application, like compression, cryptography, digital audio/video processing etc.

The best about both is, they don't exclude each other. An application can do perfectly well with a C# GUI and a C++ core.

Solver
June 9, 2007, 13:04
Originally posted by snoopy369


You mean increase competition for your potential jobs? :shame:

Just get good enough skills so you don't worry about the competition ;)

Space05us
June 9, 2007, 13:14
So how can a person now know what who to believe?

I believe I bought a book that teaches C++ so I'm going to learn C++. I do appreciate all the advice though.

I want to learn it first of all to see if I like it, and if I can even learn it. If I do like it I might transform into super-geek and turn it into a career, if I don't like it at least I learned something new. Even if I do forget it within a month I couldn't say it was a waste of time.


Hey, he got his answer...somewhere...buried in there.

Much to my embarrassment the way to fix the program wasn't exactly what the young jedi suggested, but it was in the book. Just a few paragraphs past where they explain what to do when you get any of about 5 different errors, it tells you to add in a couple of lines that makes the program pause and wait for an input to close. :blush:

VetLegion
June 9, 2007, 14:01
A call to getch() will do that, as Kuciwalker said.

Solver
June 9, 2007, 14:04
getch() isn't a real C++ function, it's a compiler extension and won't even compile everywhere :q: Non-standard stuff. You should instead can std::cin.get()

aneeshm
June 9, 2007, 14:07
Originally posted by Solver
getch() isn't a real C++ function, it's a compiler extension and won't even compile everywhere :q: Non-standard stuff. You should instead can std::cin.get()

That was what my first post was all about, Solver.

Solver
June 9, 2007, 14:11
Well, your post was very concise ;)

Koyaanisqatsi
June 9, 2007, 15:21
Originally posted by Ari Rahikkala
Most of the things that I know and that are worth saying have already been said, but I'd just like to remind you of something: Space, if you find that you will want to spend the next 30 years of your life programming, you have to understand the technical background well. Koyaanisqatsi should be thwacked over the head with a Common Lisp manual for suggesting that Java and C++ will do that right.
I agree C does it better, but C++ is now as low as many people will need to get, so that's why I think it's where new programmers should start.

Nikolai
June 9, 2007, 17:36
I took a course on C++ last year. Not my cup of tea.

int main ()
{
cout << "Listen to the smart guys::nod:" ;
return 0;
}

Solver
June 9, 2007, 18:26
Not my cup of tea.

Clearly, as your code wouldn't even compile :p

Peter Triggs
June 9, 2007, 18:26
The language of the future is LOLCODE (http://lolcode.com/) One of the WOW programmers posted this example on his blog (http://rumsey.org/blog/):


HAI
CAN HAS STDIO?
I HAS A VAR
GIMMEH VAR
IZ VAR BIGGER THAN 10 O RLY?
YA RLY
BTW this is true
VISIBLE "BIG NUMBER!"
NO WAI
BTW this is false
VISIBLE "LITTLE NUMBER!"
KTHX
KTHXBYE

Kuciwalker
June 9, 2007, 18:27
:b: :b: :b:

Nikolai
June 9, 2007, 18:56
Originally posted by Solver
Not my cup of tea.

Clearly, as your code wouldn't even compile :p

I know, I must have some include lines on top. But I didn't remember what was their names again.

VetLegion
June 9, 2007, 19:49
Originally posted by Peter Triggs
The language of the future is LOLCODE (http://lolcode.com/) One of the WOW programmers posted this example on his blog (http://rumsey.org/blog/):


HAI
CAN HAS STDIO?
I HAS A VAR
GIMMEH VAR
IZ VAR BIGGER THAN 10 O RLY?
YA RLY
BTW this is true
VISIBLE "BIG NUMBER!"
NO WAI
BTW this is false
VISIBLE "LITTLE NUMBER!"
KTHX
KTHXBYE


How can you not love the internet? Something that obviously started as someone's joke now has a standardization committee :lol:

Harovan
June 10, 2007, 02:18
Originally posted by Solver
getch() isn't a real C++ function, it's a compiler extension and won't even compile everywhere :q: Non-standard stuff. You should instead can std::cin.get()

That's not the same. std::cin.get() still works buffered and doesn't return until a whole line including the return key was entered. The non-portable getch() works on any key pressure that produces an ASCII character (just not shift, alt etc. obviously).

So you would have to do this:

std::cout << "Press ENTER to terminate" << std::endl;
std::cin.get();

;)

Sadly there is no portable way to achieve this in C/C++.

Oh, :lol: @ LOLCODE. Looks promising, albeit not very powerful.

Solver
June 10, 2007, 09:24
If the goal is to merely have the window remain on-screen, cin.get() does it. Hey, an infinite loop would do it ;) For Dev-C++, people are in the habit of using system("PAUSE") (or similar), but I quite shun the approach.

reds4ever
June 10, 2007, 09:59
Originally posted by Kuciwalker


malloc and pointers are the fun part :shame:

Get a life geekboy!!;)

Kuciwalker
June 10, 2007, 11:17
Originally posted by Solver
If the goal is to merely have the window remain on-screen, cin.get() does it. Hey, an infinite loop would do it ;) For Dev-C++, people are in the habit of using system("PAUSE") (or similar), but I quite shun the approach.

That doesn't close on input.

Harovan
June 10, 2007, 11:31
Originally posted by Solver
For Dev-C++, people are in the habit of using system("PAUSE") (or similar), but I quite shun the approach.

That's one of the reasons why I shun Dev-C++ people. ;)

The lack of a portable way to get key pressures is a big weak spot of C/C++. Go and look up portable programs that rely on it, like old PGP versions for DOS, where it's used to enter entropy for the RNG. The code is often several pages long and involves multiple #ifdefs etc. and many hacks and klugdes like ioctl() calls etc. :)

Solver
June 10, 2007, 11:41
Originally posted by Kuciwalker


That doesn't close on input.

Yes, but you should be shutting the program down from your IDE anyway if you're using it ;)

Impaler[WrG]
June 25, 2007, 17:39
I taught myself C/C++ as my first language from a cheap book and various Internet guides and some lame Dos compiler. I highly recommend it cause its hard, you will grind away at it for a month until you DREAM code, once you have mastered pointers you will know your cut out to be a programmer and the sky is the limit. So good luck :b:

Solver
June 25, 2007, 18:40
Oh come on Impaler, you know that it's not the right way to go except for people who have a natural talent at programming. You clearly do have that. But most people are likely to get scared away by C++, as they wouldn't be immediately ready to understand it without learning something else first.

Asher
June 25, 2007, 21:21
The worst C++ code I've ever seen comes from people with little to no training. It's one of the reasons most community-based open source projects are appallingly bad. FreeCiv is most definitely included there.

And a C++ developer isn't worth the air he breathes if he doesn't have a copy of the ISO standards on his desk (or in his desktop).

Harovan
June 26, 2007, 01:51
Originally posted by Asher
And a C++ developer isn't worth the air he breathes if he doesn't have a copy of the ISO standards on his desk (or in his desktop).

QFT

Solver
June 26, 2007, 08:53
Doesn't mean that training guarantees anything. Plenty of people with a CS degree write code that makes your hair stand up...

Asher
June 26, 2007, 09:31
Originally posted by Solver
Doesn't mean that training guarantees anything. Plenty of people with a CS degree write code that makes your hair stand up...
I agree that European CS programs need more quality control.

Solver
June 26, 2007, 09:35
Are you saying that American/Canadian CS programs produce quality programmers?

KrazyHorse
June 26, 2007, 09:37
Originally posted by Kuciwalker


malloc and pointers are the fun part :shame:

So why not straight C?

Kuciwalker
June 26, 2007, 09:55
That is a good question indeed. Why not?

Harovan
June 26, 2007, 09:55
TBH, if I don't really need the C++ stuff (exceptions, type-safety, STL and that) and speed matters, I'm inclined to use ANSI C. For instance I'm writing on a chess engine at my spare time at the moment, and except for system calls like threads, mutexes and timers I restrict myself to ANSI C (disabled all language extensions in the IDE and set the "treat warnings as errors" option).

C++ is all nice and dandy, but it produces a slight overhead. All function calls contain one more hidden parameter (the "this" pointer). Exceptions also take some instructions on every function call. The memory subsystem is slightly slower (as it just extends the malloc stuff). The STL classes are nice but hand-tailored hashtables are still faster. That sums up. And even if you get only 10% faster code, there's a difference if you can do, say, 100000 positions per second or 110000.

KrazyHorse
June 26, 2007, 09:56
Originally posted by Sir Ralph
Oh, :lol: @ LOLCODE. Looks promising, albeit not very powerful.

I want MC generators written in it. And I want it yesterday. :doitnow!:

Kuciwalker
June 26, 2007, 09:57
Eh, for something like a chess AI (exponential runtime) anything less than an order of magnitude improvement isn't terribly useful.

Asher
June 26, 2007, 09:57
Originally posted by Solver
Are you saying that American/Canadian CS programs produce quality programmers?
Why do you think no real software is developed in Europe?

Kuciwalker
June 26, 2007, 09:58
Originally posted by Sir Ralph
Oh, :lol: @ LOLCODE. Looks promising, albeit not very powerful.

What? It looks Turing-complete to me.

Asher
June 26, 2007, 09:58
Originally posted by Sir Ralph
TBH, if I don't really need the C++ stuff (exceptions, type-safety, STL and that) and speed matters, I'm inclined to use ANSI C. For instance I'm writing on a chess engine at my spare time at the moment, and except for system calls like threads, mutexes and timers I restrict myself to ANSI C (disabled all language extensions in the IDE and set the "treat warnings as errors" option).

C++ is all nice and dandy, but it produces a slight overhead. All function calls contain one more hidden parameter (the "this" pointer). Exceptions also take some instructions on every function call. The memory subsystem is slightly slower (as it just extends the malloc stuff). The STL classes are nice but hand-tailored hashtables are still faster. That sums up. And even if you get only 10% faster code, there's a difference if you can do, say, 100000 positions per second or 110000.
There's nothing wrong with using C. It's a great language for what it was designed for.

Asher
June 26, 2007, 10:00
Originally posted by Kuciwalker
Eh, for something like a chess AI (exponential runtime) anything less than an order of magnitude improvement isn't terribly useful.
It depends how the algorithms are implemented. I make C/C++ decisions not usually based on performance, but based on how the solution will be designed. Object Oriented isn't always better, despite what academics may tell you.

Solver
June 26, 2007, 10:00
Because you have bigger corporations over there :p Didn't Indian IT specialists get most work visas in the USA? I doubt that North American CS programs avoid all the problems European ones have. I'm sure the programs at MIT, Berkeley and the like are great, but unis do not create talent.

Asher
June 26, 2007, 10:03
Originally posted by Solver
Because you have bigger corporations over there :p Didn't Indian IT specialists get most work visas in the USA? I doubt that North American CS programs avoid all the problems European ones have. I'm sure the programs at MIT, Berkeley and the like are great, but unis do not create talent.
You're correct that unis do not create talent. The problem with Europe tends to be inherent stupidity (after all, we're talking about people not smart enough to move to the New World).

Kuciwalker
June 26, 2007, 10:03
Originally posted by Asher
It depends how the algorithms are implemented. I make C/C++ decisions not usually based on performance, but based on how the solution will be designed. Object Oriented isn't always better, despite what academics may tell you.

Object Oriented is needlessly complex for a chess AI.

Solver
June 26, 2007, 10:04
Originally posted by Asher

You're correct that unis do not create talent. The problem with Europe tends to be inherent stupidity (after all, we're talking about people not smart enough to move to the New World).

Seems that the problem with the New World tends to be inherent arrogance :cute:

Asher
June 26, 2007, 10:04
Originally posted by Kuciwalker


Object Oriented is needlessly complex for a chess AI.
I wouldn't use C nor C++ for Chess AI.

LISP :b:

Asher
June 26, 2007, 10:05
Originally posted by Solver
Seems that the problem with the New World tends to be inherent arrogance :cute:
It's not arrogance when it's provably true.

Harovan
June 26, 2007, 10:05
Originally posted by Kuciwalker
Eh, for something like a chess AI (exponential runtime) anything less than an order of magnitude improvement isn't terribly useful.

As I said, it sums up, and together with other smallish time saves you'll get that order of magnitude.

Solver
June 26, 2007, 10:08
Originally posted by Asher

It's not arrogance when it's provably true.

Hey, you'll have my eternal respect if you come up with an objective and infallible measure of intelligence. ;)

Asher
June 26, 2007, 10:10
Originally posted by Solver
Hey, you'll have my eternal respect if you come up with an objective and infallible measure of intelligence. ;)
Create two landmasses: One of old thought with old infrastructure that's overcrowded, one of infinite possibilities, ample space, and new infrastructure.

People who remain in the old, shitty place are less intelligent than those who moved on to greener pastures.

;)

Harovan
June 26, 2007, 10:13
And when due to global warming the temperature in Canada goes above -20 Celsius, they'll going to be real giants! :cute:

Asher
June 26, 2007, 10:16
Originally posted by Sir Ralph
And when due to global warming the temperature in Canada goes above -20 Celsius, they'll going to be real giants! :cute:
I wish. It's 34C and humid as hell today. :(

Harovan
June 26, 2007, 10:34
Originally posted by Kuciwalker
What? It looks Turing-complete to me.

Turing-complete and powerful are 2 different things. If it weren't turing complete, it wouldn't be fit for programming at all. But if you try to write a complex piece of software with a language that is merely "Turing-complete" but not "powerful", you're in for some real fun. ;)

Nah, give me some coding convenience and let compiler and microcode break it down to Turing code, please. ;)

Ari Rahikkala
June 26, 2007, 12:10
C++ is all nice and dandy, but it produces a slight overhead. All function calls contain one more hidden parameter (the "this" pointer).

No, they don't. Method calls do, not all function calls.

Exceptions also take some instructions on every function call.

No, they don't. Play with gcc's -S flag, and -fexceptions and -fno-exceptions one day. You'll find that you only pay for what you use.

LDiCesare
June 26, 2007, 13:43
Why do you think no real software is developed in Europe?
Yes, it's not like any of the cars, planes, computers and whatnot you're using have been designed with CATIA which happens to be French for the most part.

Harovan
June 26, 2007, 16:38
Originally posted by Ari Rahikkala
No, they don't. Method calls do, not all function calls.

If you use C++ consequently, pretty much everything you call will be a method. You don't call scanf, printf and such, but use streams (<< and >> are methods; operators implemented as methods, to be precise). You don't use strcpy et al., but use std::string. You don't link stuff together manually, but use lists, vectors, queues and such. Every access is a method. If you search through them you don't use indexed access, but iterators. Full of methods. Even algorithms and functions can be implemented as classes.

The point of this discussion is, that if you don't need this stuff and have performance concerns, you might as well use plain C.

No, they don't. Play with gcc's -S flag, and -fexceptions and -fno-exceptions one day. You'll find that you only pay for what you use.

Same goes for exceptions. It makes little sense to switch exceptions off in C++. If you don't want to use what makes C++ out of plain C, you might as well use the original.

By the way I use the poor man's version of exceptions in my chess engine code. Setjmp/longjmp works a charm on fatal errors and is even ANSI compliant.

Ari Rahikkala
June 26, 2007, 18:47
Ah, I see where we went wrong now. 'tis just a little miscommunication: I thought C++ here meant just the programming language but not any specific programming style, while you thought that it meant both the programming language and idiomatic C++ style. With your definition, of course the vast majority of function calls take the this parameter, and quite a few go through dispatch, too...

... on the other hand, with my definition, it's entirely possible to write C in C++, and in fact you can benefit from it even if you don't use C++ features (g++ seems to give more informative messages on type errors than gcc, for instance). More importantly, if you find yourself in a situation where you *do* need to use a C++ feature, it will be available to you, for the cost of nothing but itself.

Harovan
June 26, 2007, 18:59
Truth to be told, I had to force myself to go back to nice, lean C code after so many years of C++, and the only 2 things I miss is the ability to declare variables in the mid of a function body, and to a less extent the // comment.

Kuciwalker
June 26, 2007, 19:13
gcc accepts both of those.

VetLegion
June 26, 2007, 19:16
Truth to be told, I had to force myself to go back to nice, lean C code after so many years of C++, and the only 2 things I miss is the ability to declare variables in the mid of a function body, and to a less extent the // comment.

ANSI C99 standard includes both of those. Something I personally object to. I always write C to be C89 compliant and use the difference between /**/ and // to tell my C and C++ code apart at a glance.

Harovan
June 26, 2007, 19:19
gcc accepts both of those.

So does VC++ 2005, but not if you

1) Switch off language extensions
2) Set the warning level to 4 (highest)
3) Enable "treat warnings as errors"

which I did to catch sins against ANSI C.

The code would without problem compile on gcc too or any other ANSI compliant compiler. The only thing I have to do is to adapt system calls like threads, mutexes and timers, which all are in the only file that is not ANSI compliant. At the moment I have Win32 and POSIX versions of it, that should get me pretty far.

VetLegion
June 26, 2007, 19:25
They probably didn't bother to upgrade Visual Studio's C compiler to the C99 standard.

Harovan
June 26, 2007, 19:31
No, and I can't say I'm unhappy with that.

KrazyHorse
June 27, 2007, 13:16
Does anybody have a good reference/learning book for C++?

I'm already fairly competent in straight C, and I've messed around a little bit with some C++ stuff, but I'm not very good at it yet. If I end up leaving academia for the financial world then they're going to like C++ and possibly Java (which I gather is simply C++ light) experience.

Harovan
June 27, 2007, 19:21
The book of books for C++ is of course Bjarne Stroustrups "The C++ programming language". It's kind of the bible of C++ programming, written by the language's inventor. I don't know if it's good as learning book, though, I read it when I already knew C++.

VetLegion
June 27, 2007, 20:44
This one is free and has OK reviews:

http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html

Didn't read it though so I can't recommend.