C++ compiler
Post Reply
Quote
Re: C++ compiler
Posted by Edge Damodred on Fri Jan 16th at 9:08pm 2004


because if you don't the compiler's gonna bitch that it still doesn't know what "cout" is. Bow to the master that is the compiler, it is your master and you are its bitch. [addsig]



Quote
Re: C++ compiler
Posted by Crono on Fri Jan 16th at 9:23pm 2004


You include the iostream library so that the compiler can use the overloaded commands cout and cin. You don't need namespace. Especially with the GNU compiler, which he is using. I suggest you shop for some different books, because if it is the case that the book is telling you to use namespace when you're just outputting a line . . . then what else is it wrong about? This is how you can tell, does the author justify the use of namespace there? If he does. Look online in many areas to see what namespace is used for and que it up to the authors explination.

*Note: Most C++ books, believe it or not, are WRONG! Especially with templates . . . ewwww

So, Edge does that mean that when I write a compiler (in about 4 months) people will inadvertently be bowing to me? and being my bitch?? Not that it will be up to par with commercial compilers or optimized in any way.


[EDIT-Reply to Edges 1st comment below]
The really funny thing is a true 'template' could never be made using the idea of templates.
[/EDIT-Reply to Edges 1st comment below]


[EDIT-Reply to Edges 2nd comment below]
Mwa hahahaha! . . . cool.
[/EDIT-Reply to Edges 2nd comment below] [addsig]




Quote
Re: C++ compiler
Posted by Edge Damodred on Fri Jan 16th at 9:27pm 2004


Templates are seductively evil...very seductively evil, like the STL...

And if your compiler gets the program to do what the person wanted, that person WILL be your bitch .

[addsig]




Quote
Re: C++ compiler
Posted by DesPlesda on Sat Jan 17th at 2:25am 2004


Oztman, I wouldn't recommend learning C++ first. Learn C, as it's simpler (and in my opinion better) so that you understand the basics of imperative programming before you start on object-oriented coding.



Quote
Re: C++ compiler
Posted by fraggard on Sat Jan 17th at 3:35am 2004


? posted by DesPlesda
Oztman, I wouldn't recommend learning C++ first. Learn C, as it's simpler (and in my opinion better) so that you understand the basics of imperative programming before you start on object-oriented coding.

I second that. There's no real reason for a learner to be learning C++. Make sure you understand Procedure oriented programming before you shift to OO. And don't believe all the cooks out there who scream about C being outdated and C++ being "b3s+ 3v4r!!!" and all that. C++ is probably only good for very, very large applications which lose coherence with structured languages.





Quote
Re: C++ compiler
Posted by Edge Damodred on Sat Jan 17th at 3:54am 2004


C is hardly outdated, all PS2 games are written in C, and still many game dev houses use it, Bioware for one. C++ does provide a slight overhead, but the development time and object hierarchy more than make up for it. It would certainly help to understand procedural programming before learning OOP, but is not entirely necessary, although the more you know the better.

Now lets end this language debate, as fragmented this site is between editors for various games, we'll be arguing over a whole bunch of languages before the time is done.

[addsig]




Quote
Re: C++ compiler
Posted by Monqui on Sat Jan 17th at 5:53am 2004


I wish I could learn normal languages like C up here at school (as in, take a class (not geared for CIS or MIS majors) that actually went in-depth with it.)

Right now I'm taking 2 programming classes- one uses Scheme, and one uses COBOL.

Wtf.

In the past, we've done stuff with Ada (which is a miserable language- learn some other Algol based langage if you're dead set on learning something like that), Java (which might have been interesting if we really got to delve into it, but for what we were using it for, it was absolutely useless), and Assembly (which is actually really good to know, so that wasn't a total waste).

But on topic- yes. Learn something non-OO based first. Since I'm sure at this point, you aren't going to use classes, its kind of useless to learn a language for which classes play a major part, when you could just as easily teach yourself C (which provides a great foundation for scores of other languages.. [addsig]




Quote
Re: C++ compiler
Posted by DesPlesda on Sat Jan 17th at 6:33am 2004


Assembly is a really good language to learn as your first language, because it gets you understanding the underlying principles of the computar machene. I recommend Assembly Language Step-By-Step by Jeff Duntemann (ISBN 0-471-37523-3). It's designed for non-programmers, and teaches all the basics of assembly. I love it.



Quote
Re: C++ compiler
Posted by Edge Damodred on Sat Jan 17th at 7:01am 2004


The only problem with assembly is that it's machine specific, so if you list Assembly as a language you know, you had better specify for which hardware.

But yes, you can really delve deep into something know the hardware's assembly. One of my instructors wrote a hell of a lot better blitter for a mobile device over the one that was provided by the dev kit. He basically used it to find out where the hell the video memory started, a long and tedious process that payed off in spades.

Now go learn each machine's machine code

[addsig]




Quote
Re: C++ compiler
Posted by Crono on Sat Jan 17th at 7:14am 2004


If you wanted to go about learning C first, why didn't you just write in C++ and not really try object orientation. Also, just because you're using a class doesn't mean you're doing object orientation.

Secondly. I would actually suggest for a very first language, if you have no experience, Java. It has all the power C++ has and it is higher level. Then you should work your way down to C++ (which is pratically the same as C, if you know C++ you know C, you just need to change the way you do a few things). then Get down to Assembly. I found that it is much easier to learn assembly (and faster) if you have a language to base it on. This has been my experience, and Most universities experiences.

C++ is actually perfect for procedure programming, it just depends on what book you have!

I've said it before, I'll say it again:

C++ Primer Plus By Stephen Prata covers the entire language (ISBN# 1-57169-162-6) You can probably find a used copy of the 3rd edition or earlier at somewhere like Powels, if you know what that is. It would probably be like 15 bucks.

Another must have programming book is

The C Programming Language by Brian Kernighan and Dennis Ritchie (ISBN#0-13-110362-8)

That last book especially is a major milestone in standard programming syntax.

If you're looking for a Data Structures Book, you're pretty much on your own.

Simply because most people (Authors) delute what should and shouldn't be done.

If you're looking for some Java help I recommend this book:

Thinking in Java By Bruce Eckel
You can download it from his site here

Also, just for some background knowledge, Java is ONLY object oriented (if you didn't know). It's a nice language, but it has some slow runtimes (garbage collection).

Some nice aspects though are you don't have to clean up your dynamic memory, it is handled by the garbage collector.

The language is very nice and if Sun could get it to run faster it would easily replace C++ as the standard for run-time application development. [addsig]




Quote
Re: C++ compiler
Posted by fraggard on Sat Jan 17th at 8:04am 2004


? posted by Crono
C++ is actually perfect for procedure programming, it just depends on what book you have!

Er, doesn't that beat the whole purpose of C++? I'm not disputing the validity of what you said. Just the purpose . What use is C++ when C generates more efficient code in the Procedure oriented way?

And as far as books go, I've used "Herbert Schildt: C++ the complete reference" for C++ and found it very good for reference (duh!) assuming you know some programming... Also I suppose you could use "Langsam, Augenstein and Tanenbaum" for data structures (in C and C++). Slightly complicated but overall very solid.

/useless info





Quote
Re: C++ compiler
Posted by OtZman on Sat Jan 17th at 1:01pm 2004


The reason to why I'm trying to learn C++ instead of Java or C or something is that in half a year I will do a C++ beginner course at school and I plan to finish it now.

? posted by Edge Damodred

There's nothing wrong with the code in itself, it's just that console apps shut down as soon as you're finished.

You can write a batch file with the following lines

*****.exe (name of the executable)

pause

rename the text file to .bat and run it from there. Some compilers will do this for you when you run in debug mode, but not all.

That should work for you though. You could also put some kind of input statement at the end.

cout<<"Input q to quit."

char q;

cin>>q;

but that just looks bad, so go with the .bat method.

The batch file method worked, but than some other lines also were printed on the screen like "C:\Dev-cpp\[code]\>pause". The other method with the cin statement didn't work...

#include <iostream>
using namespace std;

int main()
{
cout << "My first program ";
cout<<"Input q to quit."

char q;

cin>>q;


return 0;
}

The book I'm reading from recommends Microsoft Visual C++ 6.0... I don't know if the "My first program" text would "stay" on screen if I used this program to compile...

[addsig]




Quote
Re: C++ compiler
Posted by scary_jeff on Sat Jan 17th at 1:30pm 2004


include conio.h and use getch(); at the end of the program. This will cause the program to stop at this point and exit after you press any key. I say don't bother with namespace for simple things like this because you really don't need it.



Quote
Re: C++ compiler
Posted by OtZman on Sat Jan 17th at 2:16pm 2004


Well that seems to work fine... thx a lot scary_jeff! [addsig]



Quote
Re: C++ compiler
Posted by OtZman on Sat Jan 17th at 2:46pm 2004


My program won't print letters like ? ? ? ? ... is there anything I can do about it? [addsig]



Quote
Re: C++ compiler
Posted by fraggard on Sat Jan 17th at 4:21pm 2004


You can use cout for ASCII only, I think. So I'm not sure it can print accented characters. Try an ASCII chart or print one out.

for(int i=0; i<255; i++)
{ cout<<"\n"<<(char) i ;
}

Should do it for you

Edit: http://www.jimprice.com/ascii-0-127.gif





Quote
Re: C++ compiler
Posted by OtZman on Sat Jan 17th at 5:55pm 2004


Do you mean like this?

// Ett "f?rsta" exempel
#include <iostream>
#include <conio.h>
using namespace std;


int main()
{
cout << "Mitt f?rsta program";
getch();
for(int i=0; i<255; i++)
{ cout<<"\n"<<(char) i ;
}


return 0;
}

It didn't work

[addsig]




Quote
Re: C++ compiler
Posted by Monqui on Sat Jan 17th at 6:04pm 2004


Kinda yes, kinda no. First off- lemme explain this code:

for(int i=0; i<255; i++)
{ cout<<"\n"<<(char) i ;
}

Dunno if you're familiar with this construct- its called a for loop. Basically, it initializes an integer variable (in this case, i) to be = to 0. Then, the body of the loop executes (the 'cout <<"\n"<<(char) 1;' part) for i = 0. When that is finished, it evaluates the i<255 clause, and if it is true, then it increments i, and executes the loop body again.

It continues this pattern of incrementing/executing/checking unit the i<255 part returns false (or, when i is greater than or = to 255).

The (char) part is what is known as Casting- basically, you are telling it to output i in terms of a character, instead of an integer (without it, all this program would do would print the numbers 1 to 255 on the screen).

So what tha code is supposed to do is output all 255 characters in the ASCII dataset onto the screen.

Oh, and "\n" is a character (technically only ONE character) that prints out a new line.

But, I think you're running into the same case as before- the program is outputing information to the screen, and then closing before you get a chance to see it. Add another getch() afterwords.

You should see the last few characters in the ASCII dataset.

If you want to fit them all on the screen, replace the "\n" part of the loop body with a "\t" (it moves the cursor to the next tab break). [addsig]




Quote
Re: C++ compiler
Posted by OtZman on Sat Jan 17th at 6:54pm 2004


I've never heard of a loop before. I'm totally new to programming, but I thing I start to understand what a loop is, but I don't get how to make letters like ?, ?, ? to appear on my screen

[addsig]



Quote
Re: C++ compiler
Posted by Monqui on Sat Jan 17th at 7:21pm 2004


What you would have to do is use some other character set than ASCII. How you would go about using this, I don't know. Never really had a reason to do it. Sorry bud. [addsig]




Post Reply