Author Topic: Coding and Scripting > Learning C++  (Read 12431 times)

Offline Village Idiot

  • Hero Member
  • *****
  • Posts: 2345
  • Have A Nice Day.
Re: Coding and Scripting > Learning C++
« Reply #30 on: December 04, 2009, 05:47:55 PM »
Quote
Don't know if it will help, but did you save the file with a new line after the code. I did a copy/paste too, ended with a new line before saving, and it compiled for me also.
   

Thanks OP, but yeah that was the first thing I did after Chomp mentioned the copy/paste issue. And yeah, there was no newline. -whoops- I should know better. Odd the compiler didn't mention it as it does with when ever I do anything in C. I always seem to make that mistake somewhere along the way.

But it didn't fix it..Same result.


What editor did you use?


Errr.. ummm.. arrhh...eerr  Kwrite   :P
$ fortune
No Microsoft products were used in any way for the creation of this message.
If you are using a Microsoft product to view it, BEWARE! - I'm not
responsible for any harm you might encounter as a result.

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15829
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Coding and Scripting > Learning C++
« Reply #31 on: December 04, 2009, 06:26:46 PM »
Try scribes instead.


Offline Joble

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6804
  • USA - Mountain Time
Re: Coding and Scripting > Learning C++
« Reply #32 on: December 04, 2009, 06:44:26 PM »
I think you must be missing something, cause it works here.   ???  (Not missing something, like you don't know, but missing something, like a file or package)
[joe@localhost Documents]$ g++ hello.cpp
[joe@localhost Documents]$ ./a.out
Hello World!
[joe@localhost Documents]$
Search First.
Forum Rules
Hero means I talk a lot, nothing more, nothing less!
Have an Awesome Day!
Healthy System

Offline gseaman

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 3881
Re: Coding and Scripting > Learning C++
« Reply #33 on: December 05, 2009, 04:51:25 PM »
Neal, you are doing fine job. Posting code to be dissected prompted a very thorough conversation and I learned a few things. The teacher assignment was just a prompt to get things going from my point of view. Everyone here has a lot to contribute and I will do my best to keep up.

Galen

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15829
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Coding and Scripting > Learning C++
« Reply #34 on: December 05, 2009, 05:37:36 PM »
LOL I'm hoping I can keep up.  ;D


Offline Chomp

  • Full Member
  • ***
  • Posts: 173
Re: Coding and Scripting > Learning C++
« Reply #35 on: December 28, 2009, 06:32:41 PM »
These forums have been really dead lately(I imagine due to the holidays) and I myself have been rather busy with an increased work schedule and the holidays.  Now that things are back to "normal" for me I've found the time to get back into C++.  I'm just curious as to if other people are still trying to learn and how the progress is going.  So... how's it going?

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15829
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Coding and Scripting > Learning C++
« Reply #36 on: December 28, 2009, 07:04:57 PM »
Yep! I've been busy. Holidays and other stuff, too. I've not been able to give this the attention it deserves. There will always be times when I will fall behind a bit (projects I'm committed to) and then need to catch up with you guys.

Offline Old-Polack

  • Administrator
  • Super Villain
  • *****
  • Posts: 11688
  • ----IOFLU----
Re: Coding and Scripting > Learning C++
« Reply #37 on: December 28, 2009, 07:39:53 PM »
Same here. I doubt anyone will be bothered if this doesn't continue until after the New Year, and maybe even a little more, for things to normalize again.
Old-Polack

Of what use be there for joy, if not for the sharing thereof?



Lest we forget...

Offline gseaman

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 3881
Re: Coding and Scripting > Learning C++
« Reply #38 on: December 28, 2009, 11:49:52 PM »
I'm still here, following the postings. I'm not doing much coding, but I have packaged a couple of kernels (for fun in my free time) and a couple of other PCLinuxOS things... ;D

Offline Village Idiot

  • Hero Member
  • *****
  • Posts: 2345
  • Have A Nice Day.
Re: Coding and Scripting > Learning C++
« Reply #39 on: December 31, 2009, 04:21:05 AM »
These forums have been really dead lately(I imagine due to the holidays) and I myself have been rather busy with an increased work schedule and the holidays.  Now that things are back to "normal" for me I've found the time to get back into C++.  I'm just curious as to if other people are still trying to learn and how the progress is going.  So... how's it going?

Well, on boxing day (dec. 26th), I got to compile and run some c++ code by accident. The program is called ext3grep and it successfully undeletes the files that were in your 3Gb /home partition after you -really- cleanup your files after you've been drinking.  :o Fatal mistake.. doing a 'lint' before doing the backup.  :( 

http://groups.google.com/group/ext3grep/web/ext3grep-source-code-and-overview

And in case you're wondering.. Yes, it does work. No, I wouldn't recommend behaving careless or reckless enough to have to rely on it.  ;)

Closest I've been to catastrophe in a loooong time.  :)

I made a post in the shoot-yerself-in-da-foot thread only a few hours prior to this incident. There seems to be a pattern....
http://www.pclinuxos.com/forum/index.php/topic,66495.msg543556.html#msg543556
$ fortune
No Microsoft products were used in any way for the creation of this message.
If you are using a Microsoft product to view it, BEWARE! - I'm not
responsible for any harm you might encounter as a result.

Offline wedgetail

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 2469
  • Any Bugs in site?
Re: Coding and Scripting > Learning C++
« Reply #40 on: January 21, 2012, 10:17:09 PM »
When this thread started I fell off, I was too lost and did not have a clear motivation at the time.
Now I have motivation to continue with a bit of beginner programming in C, then I can later advance to C++.  The reason to start in C is that I have found a small program that has given me a goal to try and see how far I can get, ie I am motivated  :)  

I have been reading lot in this area, have a lot of information in my head. just can't get it to come together. Let me get to the usual starting point, "hello world".

I have a directory set aside for this simple experiment.

Code: [Select]
[gert@localhost conly]$ ls -l
total 12
-rwxr-xr-x 1 gert gert 5564 Jan 22 15:51 ctest_hello*
-rw-r--r-- 1 gert gert  113 Jan 22 15:50 ctest_helloworld.c
[gert@localhost conly]$


The follwoing I took to mean I have C compiler?
Quote
[gert@localhost conly]$ gcc
gcc: no input files
[gert@localhost conly]$

Would probably have been a bit smarter trying to work out the version number with gcc -v, whilst getting this it also looks a bit intimidating.  Consulting gcc --help reveals that the statement shows files called by gcc

Quote
[[root@localhost ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i586-mandriva-linux-gnu/4.5.2/lto-wrapper
Target: i586-mandriva-linux-gnu
Configured with: ../configure --prefix=/usr --libexecdir=/usr/lib --with-slibdir=/lib --with-bugurl=https://pclinuxos.com/ --mandir=/usr/share/man --infodir=/usr/share/info --enable-checking=release --enable-languages=c,c++,ada,fortran,objc,obj-c++,java --build=i586-mandriva-linux-gnu --host=i586-mandriva-linux-gnu --with-cpu=generic --with-system-zlib --enable-threads=posix --enable-shared --enable-objc-gc --enable-long-long --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --enable-java-awt=gtk --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-gtk-cairo --disable-libjava-multilib --enable-ssp --disable-libssp --disable-werror --with-python-dir=/lib/python2.6/site-packages --enable-lto --enable-plugins
Thread model: posix
gcc version 4.5.2 (GCC)
[root@localhost ~]# gcc -V
gcc: '-V' option must have argument
[root@localhost ~]#

Got the version gcc version 4.5.2 (GCC)  and guessing upper case V did not do better. Leave it at that.


Copied content below from critters post in the nearby thread, as it was stated to be C code. I copied the text into kwrite and saved the file.  Got a bit carried away with file names, I regret that as it is more typing  :D

Code: [Select]
[gert@localhost conly]$ cat ctest_helloworld.c

#include <stdio.h>

int main()
{
printf("Hello PCLinuxOS user!"
" I like the number 9"
" for some reason.\n");
}[gert@localhost conly]$

Then compiled as below
Code: [Select]
[gert@localhost conly]$ gcc ctest_helloworld.c -o ctest_hello
[gert@localhost conly]$

The file ctest_hello shows up, and it is not text file, so assuming it is binary but not yet .exe or something.

Question, how can I run this file?  Or is that the stage where one must go looking for make

Edit:
When I started on this exercise, I got the impression that to make a running program, as simple as this, all that was needed was the line something like, gcc ctest_helloworld.c -o ctest_hello and that my exe file was the last filename.

I took a break because my head was spinning a bit too much, coming back I got the bright idea of search the Internet for: compiling c programs from what I pick up I am on the right track.

I guess the next step is called debugging nothing to do with make

a.out
Reading through the section here I came across the a.out where did that belong, another penny dropped

Quote
[gert@localhost conly]$ gcc ctest_helloworld.c #this produces the a.out file haaah this is where it comes from
[gert@localhost conly]$

Red portion above is probably the simplest form of a compile statement, the default file output is a.out
Could not help trying out the use of # on the command line to annotate what is presently going on. The command line interpreter ignores what comes after the #.

In the mean time I remembered something old-polack mentioned some time ago when apparently I must have been trying to run an exe file, you use ./ in front of the file to indicate run from present position, even though you are already in the directory, ie my present position already is correct, that one beats me.  ;D

Well I will suggest the for a C program the "Hello World" is changed a bit, something like :D

Quote
[gert@localhost conly]$ ./a.out
Hello PCLinuxOS user! when you have the result of the gcc xxxx.c to use ./<exefile_name> to start the program and by the way to use ctl-C to bail out
[gert@localhost conly]$

gcc and option -o
This option is used to specify a none default output file such as in my compile run gcc ctest_helloworld.c -o ctest_hello
the output file is ctest_hello

Well this was my warm up to a problem, which I now have to and find again. This other program have decided to play hide and seek. I will take a brake though as last time that gave beneficial result.
« Last Edit: January 22, 2012, 03:38:54 AM by wedgetail »
32 bit: KDE (older) & various KDE-mini, ASUSTek P5P41D Rev X.0x, BIOS AMI0207 07/21/2009, "Pentium(R) Dual-Core CPU E5300 @ 2.60GHz", nVidia GeForce 9600 GT, 2x1GB Seagate Technology 1000528AS HDD
TV CompuPro VideoMate Vista E700 (not working in Linux), Acer X243HD LCD Screen

Offline wedgetail

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 2469
  • Any Bugs in site?
Re: Coding and Scripting > Learning C++
« Reply #41 on: January 22, 2012, 03:47:06 AM »
The program I really would like to try out, a parallel port diagnostic utility, is found here.

http://yyao.ca/projects/ParallelPortLinux/

The project is stretching my ability but I am rather keen to have a go.  From what I can understand, this involves using at least one window and I think the window part is what requires GLUT.  

Quote
Using the keyboard, you can view and change the pins on your parallel port. You will need to install the GLUT development packages to compile this (e.g. freeglut3-dev)


I have searched Synaptic using "glu" and come to the conclusion that some form of GLUT is already installed in PCLOS. I am intending to use KDE-mini.

Before I go any further I would like ask if I am right the need for a GLUT has already been provided?   :)



« Last Edit: January 22, 2012, 03:48:46 AM by wedgetail »
32 bit: KDE (older) & various KDE-mini, ASUSTek P5P41D Rev X.0x, BIOS AMI0207 07/21/2009, "Pentium(R) Dual-Core CPU E5300 @ 2.60GHz", nVidia GeForce 9600 GT, 2x1GB Seagate Technology 1000528AS HDD
TV CompuPro VideoMate Vista E700 (not working in Linux), Acer X243HD LCD Screen

Offline AS

  • Hero Member
  • *****
  • Posts: 4098
  • Have a nice ... night!
Re: Coding and Scripting > Learning C++
« Reply #42 on: January 22, 2012, 06:15:12 AM »
The program I really would like to try out, a parallel port diagnostic utility, is found here.

http://yyao.ca/projects/ParallelPortLinux/

The project is stretching my ability but I am rather keen to have a go.  From what I can understand, this involves using at least one window and I think the window part is what requires GLUT.  

Quote
Using the keyboard, you can view and change the pins on your parallel port. You will need to install the GLUT development packages to compile this (e.g. freeglut3-dev)


I have searched Synaptic using "glu" and come to the conclusion that some form of GLUT is already installed in PCLOS. I am intending to use KDE-mini.

Before I go any further I would like ask if I am right the need for a GLUT has already been provided?   :)




 ::) ::) ::)

the libraries you are searching for are:

libmesaglut3-devel-7.11.2-1pclos2011
libmesaglut3-7.11.2-1pclos2011

to compile c++ code, you will need gcc-c++ (not installed by default)

Have a nice Sunday! ;D

AS

Offline wedgetail

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 2469
  • Any Bugs in site?
Re: Coding and Scripting > Learning C++
« Reply #43 on: January 22, 2012, 07:34:02 AM »
as
Thank you, I have downloaded from the site and 'untarred' a short while ago and my spirit dived a bit as I realised I was already advancing to C++, which was not quite what I had expected. I will follow up on installing more programs but in another system.

I am taking another brake and will set up another partition with KDE-mini, starting to take too many chances here in present system. Also way past Sunday and my ZZzzzz time.
32 bit: KDE (older) & various KDE-mini, ASUSTek P5P41D Rev X.0x, BIOS AMI0207 07/21/2009, "Pentium(R) Dual-Core CPU E5300 @ 2.60GHz", nVidia GeForce 9600 GT, 2x1GB Seagate Technology 1000528AS HDD
TV CompuPro VideoMate Vista E700 (not working in Linux), Acer X243HD LCD Screen

Offline wedgetail

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 2469
  • Any Bugs in site?
Re: Coding and Scripting > Learning C++
« Reply #44 on: January 23, 2012, 07:29:10 PM »
Set up my new OS partition (KDE-mini) and installed the extras to get to c++ capability

Quote
Commit Log for Mon Jan 23 15:19:29 2012
Installed the following packages:
gcc-c++ (4.5.2-4pclos2011)
libstdc++-devel (4.5.2-4pclos2011)


Then got sidetracked a bit having found something about the use of a shell to ease the options, random internet search:
http://www.arachnoid.com/cpptutor/setup_unix.html

Quote
#/bin/sh
echo compiling C++ using -ansi -pedantic-errors -Wall
g++ -ansi -pedantic-errors -Wall $1 $2 $3


Save in a file called gccp, did not work to well, claimed no input file,

Code: [Select]
[gert@localhost ParallelPortTest]$ ./gccp temp.cc
compiling C++ using -ansi -pedantic-errors -Wall
g++: no input files
[gert@localhost ParallelPortTest]$

I thought temp.cc=$1 perhaps  the $2 and $3 need to be defined, gave up on that decided to do it by hand:

[gert@localhost ParallelPortTest]$ g++ -ansi -pedantic-errors -Wall temp.cc
[gert@localhost ParallelPortTest]$ ./a.out
Hello World! this is gert and his first c++ attempt =====   ==== >>>>>>>>
[gert@localhost ParallelPortTest]$

This worked fine, so now I am c++ programmer  :)

Because the parapllelport program had a 'make' file:

Quote
[gert@localhost ParallelPortTest]$ make
g++ -ansi -Wall ParallelPort.cpp main.cpp -lGL -lglut -o ParallelPortTest
In file included from main.cpp:31:0:
main.h:39:21: fatal error: GL/glut.h: No such file or directory
compilation terminated.
make: *** [ParallelPortTest] Error 1
[gert@localhost ParallelPortTest]$


Well I edited the Make file

Code: [Select]
SRC = ParallelPort.cpp main.cpp
TARGET = ParallelPortTest
CXX = g++
CXXFLAGS = -ansi -Wall
# LIBS = -lGL -lglut
LIBS = -llibmesaglut3-7.11.2-1pclos2011 -llibmesaglut3-devel-7.11.2-1pclos2011



all: $(TARGET)

$(TARGET): $(SRC)
$(CXX) $(CXXFLAGS) $(SRC) $(LIBS) -o $(TARGET)

clean:
rm -rf $(TARGET)

It is not helping  :D

Code: [Select]
[gert@localhost ParallelPortTest]$ make
g++ -ansi -Wall ParallelPort.cpp main.cpp -llibmesaglut3-7.11.2-1pclos2011 -llibmesaglut3-devel-7.11.2-1pclos2011 -o ParallelPortTest
In file included from main.cpp:31:0:
main.h:39:21: fatal error: GL/glut.h: No such file or directory
compilation terminated.
make: *** [ParallelPortTest] Error 1
[gert@localhost ParallelPortTest]$

Ummm, perhaps not a c++ programmer just yet  ;D  looking into above, from main.h

Quote
#include <string.h>
//   #include <GL/glut.h>
#include <libmesaglut3-7.11.2-1pclos2011>

#include "ParallelPort.h"


I made a wild guess and commented out the "problem" and installed my own include file. This did not work either. Looks like I am in a pickle  ;D
« Last Edit: January 23, 2012, 07:49:09 PM by wedgetail »
32 bit: KDE (older) & various KDE-mini, ASUSTek P5P41D Rev X.0x, BIOS AMI0207 07/21/2009, "Pentium(R) Dual-Core CPU E5300 @ 2.60GHz", nVidia GeForce 9600 GT, 2x1GB Seagate Technology 1000528AS HDD
TV CompuPro VideoMate Vista E700 (not working in Linux), Acer X243HD LCD Screen