The environment of C + + programing in Linux

Source: Internet
Author: User

1. Familiar with Linux, VI and g++ programming environment;
2. Compile simple C + + program and run;
3. familiar with C + + editing, compiling, connecting and running process;

4. Ability to use C + + standard input/output stream for keyboard input and screen output.

1. Personal directory Planning and VI editor common commands:
(1) After logging into the Linux system, set up the Cpp-lab directory under the personal system directory, and then set up each experiment directory in this directory.
(2) Practice VI Common commands, master the basic usage
2. Use VI to build a standard C + + program and compile and run the following program through g++:

Specific experimental steps:
(1) Start VI Editor
Enter VI hello.cpp on the Linux command line to open the VI editor.

(2) Enter insert mode
Press I to enter insert mode and enter the following program code.

(3) Exit insert mode
When the program is finished editing, press ESC to exit Insert mode, and then press ":" to enter the last line mode.
(4) Save and return to the Linux command line
After the ":" Prompt, enter Wq to save and return to the Linux command line.
(5) Program compilation
On the Linux command line, enter the g++ compile command.

In the Linux command line input g++ compile the command compiler
(6) Running the program
On the Linux command line, enter the./hello to run the program.

program compile and run results


3. Write a C + + program that calculates the maximum value of two integers and requires that the main function and the Max function be used to write the file.
4. Write a C + + program, enter two integer variables, and use the function to realize the exchange of two values.
5. Let the computer randomly give a positive integer within 100 to let the person guess, if guessed, the computer gives the correct hint and gives the total number of guesses, and then quit the game. Otherwise the error is given and the number of guesses is big or small. The game guesses up to 10 times, and if it is still not guessed within 10 times, the prompt fails and exits the game.


#include <iostream> #include <time.h>using namespace Std;int main () {int num,x,i=0;time_t t;srand ( &t) Num=rand ()%100;cout<< "Guess my number!\nyou has times.\n"; while (cin>>x) {i++;if (x==num) { cout<< "Good!you guess the number." <<endl;break;} else if (x>num) {cout<< "Your number is too big!\n";} else if (x<num) {cout<< "Your number is too small\n";}    if (i==10) {cout<< "you FAIL the GAME!!! \ n "; break;}   } cout<< "You guess Times:" <<i<<endl;return 0;}


Results: 1-3 operation result: [[email protected] ~]# cd/c[[email protected] c]# g++ 11.cpp 12.cpp-o 1[[email protected] c]#./1please input A and B23max = 3[[email protected] c] #猜数: [[email protected] ~]# cd/cpp-lab/shiyan1/[[email protected] shiyan1]# LS1      1.cpp~  2.cpp~  3.cpp~  4.cpp   5.cpp   Hello      hello.cpp~1.cpp  2.cpp   3.cpp   4.c~    4.cpp~  5.cpp~  



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The environment of C + + programing in Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.