Linux C ++ self-study notes

zhaozj2021-02-17  67

Linux C self-study notes 1, install the system, don't say it, I installed RedHat Linux 7.2, the installation process is intelligent, the price is not expensive (

9CD 500 Page Handbook Total 69RMB), everyone also supports support for genuine, and some simple commands ls - column directory CD - enter the directory Man - Help GCC - Compiler

2, the text editor is like to use VI, find that it is not very easy to use, find an advanced editor under the graphical interface, when the file is .c or

After .CPP, the keyword automatically displays (huh, huh, more handsome than Windows), supports mining fingers ^ i, catch

Join Favorites, menu location in Kde Menus-> Editors-> Advanced Editor

3, compile C- "Hello World!" # Include

INT main (void) {printf ("Hello World! / N"); return 0;} The storage is hello.c Entering the command line: gcc hello.c -o hello (pay attention to the case) may have Warning as follows: no newline at end of file is finally made in the file, and then execute the file: ./ Hello huh, Hello World! Cute words come out

4, compile C - "Hello World!" # Include

INT main () {cout << "Hello World! / N" << Endl; Return 0;} Compile error: undefined reference to 'cout'! How can I don't know how Cout, hurry to see how MAN says: Man GCC Oh, I originally compiled C programs G hello.cpp -o hello

5, the compilation class has three files: hello.h, hello.cpp, myfirst.cpp, the content is as follows: file: //hello.h#ifndef Helloh # define Helloh

Class Hello {Hello (); void display ();

File: //hello.cpp#include "Hello.h" #include

Hello :: hello () {}

Hello :: Display () {cout << "Hello World! / N" << endl;}

File: //myfirst.cpp#include #include "Hello.h"

Int main () {hello thehello; thehello-> display ();

Return 0;} Start compilation: g myfirst.cpp -o myfirst Yeah, error: undefined reference to 'Hello :: Hello (void)' undefined reason to 'Hello :: Display ()' Oh, it seems that hello is linked. CPP error, first change in myfirst.cpp: change #include "hello.h" to #include "hello.cpp" compile, in the picture , Play the empire, look at the book at night, and then come back tomorrow.

转载请注明原文地址:https://www.9cbs.com/read-31190.html

New Post(0)