Compiling CPP files using G ++ in Linux

Source: Internet
Author: User

This afternoon, ubuntu (I am using Ubuntu 9.10) is very useful. It is a good operating system for Linux beginners. Since I have just been familiar with C ++, I cannot help writing C ++.ProgramEnthusiasm. So I wrote a very simple C ++ program.

 

Code:( Hellocpp. cpp)

1 # include <iostream>
2 void main (){
3 using namespace STD;
4 cout <"Hello CPP !! "<Endl;

5}

 

Then compile g ++ hellocpp. cpp-O hellocpp

Error: Hello. cpp: 2: Error: ': main'. 'int' must be returned'

The result of a query on the internet proves that this is a problem with the compiler. For the time being, you can change it back to int.

 

It is said that Vim is a very powerful Linux text editor, so I want to see how powerful it is.

According to the general habit of installing software in Ubuntu, I skillfully input sudo apt-Get install Vim on the terminal, and the following prompt appears:

Reading the package list... complete

Analyzing the dependency tree of the software package

Reading status information... complete

Some software packages cannot be installed. If you are using an unstable release, this may be

This is because the system cannot meet your requirements. This version may contain software you need.

Packages have not yet been created or they are still in the incoming directory.

The following software packages have dependency that cannot be met:

VIM: Dependency: vim-common (=. 1.314-3ubuntu3. 1) But. 2.079-1ubuntu5 is about to be installed

E: software packages that cannot be installed

That is to say, the installation fails.

There are several answers when I search for the Internet, but the first one is successful (luck is a bit good). It is said that the version provided by the software source is relatively low. Originally, ubuntu was pre-installed with vim-tiny (a very lightweight Vim), So I uninstalled vim-tiny and the vim-common on which it depends, then reinstall Vim. This installation is successful.

 

When a person is addicted to something, he is often unable to extricate himself. When Vim is installed, I can't wait to start writing CPP, but it is disappointing that there is no syntax highlighting. Is there a syntax highlighting function ?! Just like buying a fake product, it is uncomfortable. But now, there must be something wrong with it. Open my favorite Google (not long before the child was forced to leave China) and find a solution like this after screening:



1

, Configuration file location


In the Directory


/Etc/


Below, there is


Vimrc

File, which is public in the system
Vim
Configuration file, which is valid for all users. (PS: if this file is not available, create one by yourself)

2

Set syntax highlighting


1)


Open


Vimrc


To highlight the Syntax:

Syntax on

2)


If the syntax is still not highlighted


/Etc


Directory


Profile


Add the following statement to the file:

Export term = xterm-color



3




, Settings

Windows

Style

C/C ++

Auto indent (Add the following

Set

Statement

Vimrc

Medium)


1


)


Set the (soft) tab width


4


:

Set tabstop = 4


Set softtabstop = 4

2


)


Set the number of spaces for indentation.


4

Set shiftwidth = 4


3


)


Set automatic indent


:That is, the indent value of each line is equal to that of the previous line.



Noautoindent


Unset:

Set autoindent

4


)


Set


Use


C/C ++


Automatic language indentation:

Set cindent


5


) Settings


C/C ++


Specific language indentation


:

Set cinoptions = {s, T0, N-2, P2s, (03 S, =. 5 S,> 1 s, = 1 s,: 1 s


6


) To display the line number of the text on the left, use the following statement:

Set nu


7


) Finally, if the following statements are not available, add them:

If & term = "xterm"

Set t_co = 8

Set t_sb = ^ [4% DM

Set t_sf = ^ [3% DM

Endif

After the setting, when we open the CPP file we just compiled again, the syntax highlight is displayed as expected.


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.