LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C++: Where to begin? (https://www.linuxquestions.org/questions/programming-9/c-where-to-begin-772216/)

johngreenwood 11-29-2009 01:37 AM

C++: Where to begin?
 
Hello, I am trying to learn C++ and will be making and compiling everything on Linux.
I am wondering, does anyone know of any good free online resources with some good tutorials and explanations?
I've been looking but I can only seem to find ones which assume a Windows development environment.

Thanks for your help.

Sergei Steshenko 11-29-2009 02:15 AM

Quote:

Originally Posted by johngreenwood (Post 3772926)
Hello, I am trying to learn C++ and will be making and compiling everything on Linux.
I am wondering, does anyone know of any good free online resources with some good tutorials and explanations?
I've been looking but I can only seem to find ones which assume a Windows development environment.

Thanks for your help.

Enter into your favorite search engine

C++ tutorial
.

I must admit MSDN has pretty good C++ tutorial - of course, nothing related to Linux, but good language coverage.

Under Linux you should get familiar with

GNU toolchain

; at the top of this forum there is "List of Free Software and Freeware IDEs":


http://www.linuxquestions.org/questi...e-ides-469623/ .

Start learning about KDevelop, CodeBlocks - off the top of my head.

But, the main thing, learn to develop in pure text environment, i.e. learn to understand what is _really_ happening.

johngreenwood 11-29-2009 02:30 AM

Thank you Sergei, I will look into those things. I will be doing it in pure text too, Vim is my editor of choice, and I will be using it a lot.

Sergei Steshenko 11-29-2009 03:02 AM

Quote:

Originally Posted by johngreenwood (Post 3772951)
Thank you Sergei, I will look into those things. I will be doing it in pure text too, Vim is my editor of choice, and I will be using it a lot.

My point regarding text environment is less of favorite text editor, but more of how various tools on the way are called and what they are doing.

I.e. how compiler is called, how, if necessary, to obtain assembly listing (if you have doubts in compiler and/or want to learn how things work inside), how, if/when necessary, preprocessor is called separately, ditto linker.

By the way, look up

Linux dynamic libraries HOWTO
.

And, look up

GNU libtool

- helps to deal with libraries/linking in general, and on simple examples I tried can even be used (in the presence of other cross-tools) to produce an executable and DLLs for Windows under Linux. Or just on one processor architecture (say, x86) to produce executables for another (say, ARM).

khodeir 11-29-2009 03:31 AM

if you want my idea try to search about C++ videos
videos are more helpful and interesting than reading
best wishes

Sergei Steshenko 11-29-2009 03:36 AM

Quote:

Originally Posted by khodeir (Post 3772986)
if you want my idea try to search about C++ videos
videos are more helpful and interesting than reading
best wishes

I'm just wondering how one is supposed to copy-paste text from video.

At all, I think learning a programming language from video is a very awkward idea.

johngreenwood 11-29-2009 03:43 AM

Thank you again Sergei, while I don't really understand any of that stuff yet, I am sure I will learn about it pretty soon. I have written my first C++ program now, it is extremely simple and doesn't really do anything, but it works.

Thank you for your suggestion khodeir, I agree, sometimes videos do make things a little more digestible, but I know that what I am trying to learn isn't just going to sink in immediately, it's going to take a lot of study and practice, and doing the same things over and over again until they become habit.
I find it is much easier to read something, then re-read it, and read it some more, rather than keep rewinding a video.

johngreenwood 11-29-2009 05:41 AM

I've had a little play around with some simple programs, and I have decided to do something real. I am trying to "translate" one of my shell scripts to C++, but I can't find out how to run commands from my program and find the exit status.

I want to find out if a process is running, and kill it if it is.

khodeir 11-29-2009 06:07 AM

give an example and let me see if i can help or not :)

johngreenwood 11-29-2009 06:21 AM

Ok, in my original script I used this:
Code:

for i in something something_else
do
  ps -A | grep -q $i
  if [[ "$?" == "0" ]]
  then
    killall $i
    if [[ "$?" == "0" ]]
    then
      echo "Process terminated"
    else
      [..do it again..]
    fi
  fi
done

I am trying to do the same thing with C++, I have made a for loop, but the names of the processes I am looking for are now held in an array.

khodeir 11-29-2009 06:36 AM

look
you must do some programs ur self or get them from internet
like grep
I am sorry to say it will take long time to implement each instruction and pipe line :)
if you want to practice C++ try editing files it will be a very good practice you will use all things u have learned

johngreenwood 11-29-2009 06:39 AM

Haha, ok. Thank you, I knew before I started it was going to be hard but I thought there would be some way to do this.

EDIT:
I found a way to run the commands from my program, but how do I know what it returned?
Code:

for(myFor=0;myFor<=1;myFor++) {
  isItRunning = "ps -A | grep -q " + procKill[myFor];
  system(isItRunning.c_str());
}


Sergei Steshenko 11-29-2009 07:45 AM

Quote:

Originally Posted by johngreenwood (Post 3773122)
Ok, in my original script I used this:
Code:

for i in something something_else
do
  ps -A | grep -q $i
  if [[ "$?" == "0" ]]
  then
    killall $i
    if [[ "$?" == "0" ]]
    then
      echo "Process terminated"
    else
      [..do it again..]
    fi
  fi
done

I am trying to do the same thing with C++, I have made a for loop, but the names of the processes I am looking for are now held in an array.

Well, maybe you should try to use /proc to find processes - probably it's more natural in C/C++.

And read

man 2 kill
.

johngreenwood 11-29-2009 11:50 AM

Ok, I now have a way to get the process ID, now I need to learn how to use that kill command you just gave me.

Code:

int kill(pid_t pid, int sig);
I'm not sure what to make of this, are pid_t and pid going to be just one thing? The process ID?

And I guess that sig will be a number, and man 7 signal tells me that SIGKILL has a value of 9.

So is that it?
Code:

kill(pid,9);
Should it look like that, or something else?

smeezekitty 11-29-2009 12:06 PM

Quote:

Originally Posted by johngreenwood (Post 3773426)
So is that it?

Yes.


All times are GMT -5. The time now is 02:28 AM.