预备知识javascript
" 显示行号 set number " 显示标尺 set ruler " 历史纪录 set history=1000 " 输入的命令显示出来,看的清楚些 set showcmd " 状态行显示的内容 set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} " 启动显示状态行1,老是显示状态行2 set laststatus=2 " 语法高亮显示 syntax on set fileencodings=utf-8,gb2312,gbk,cp936,latin-1 set fileencoding=utf-8 set termencoding=utf-8 set fileformat=unix set encoding=utf-8 " 配色方案 colorscheme desert " 指定配色方案是256色 set t_Co=256 set wildmenu " 去掉有关vi一致性模式,避免之前版本的一些bug和局限,解决backspace不能使用的问题 set nocompatible set backspace=indent,eol,start set backspace=2 " 启用自动对齐功能,把上一行的对齐格式应用到下一行 set autoindent " 依据上面的格式,智能的选择对齐方式,对于相似C语言编写颇有用处 set smartindent " vim禁用自动备份 set nobackup set nowritebackup set noswapfile " 用空格代替tab set expandtab " 设置显示制表符的空格字符个数,改进tab缩进值,默认为8,现改成4 set tabstop=4 " 统一缩进为4,方便在开启了et后使用退格(backspace)键,每次退格将删除X个空格 set softtabstop=4 " 设定自动缩进为4个字符,程序中自动缩进所使用的空白长度 set shiftwidth=4 " 设置帮助文件为中文(须要安装vimcdoc文档) set helplang=cn " 显示匹配的括号 set showmatch " 文件缩进及tab个数 au FileType html,python,vim,javascript setl shiftwidth=4 au FileType html,python,vim,javascript setl tabstop=4 au FileType java,php setl shiftwidth=4 au FileType java,php setl tabstop=4 " 高亮搜索的字符串 set hlsearch " 检测文件的类型 filetype on filetype plugin on filetype indent on " C风格缩进 set cindent set completeopt=longest,menu " 功能设置 " 去掉输入错误提示声音 set noeb " 自动保存 set autowrite " 突出显示当前行 set cursorline " 突出显示当前列 set cursorcolumn "设置光标样式为竖线vertical bar " Change cursor shape between insert and normal mode in iTerm2.app "if $TERM_PROGRAM =~ "iTerm" let &t_SI = "\<Esc>]50;CursorShape=1\x7" " Vertical bar in insert mode let &t_EI = "\<Esc>]50;CursorShape=0\x7" " Block in normal mode "endif " 共享剪贴板 set clipboard+=unnamed " 文件被改动时自动载入 set autoread " 顶部底部保持3行距离 set scrolloff=3
完整的编译并执行cpp文件过程php
(一)代码编写 html
#include <iostream> int main(void) { std::cout << "hello, world" << endl; return 0; }
gcc -Wall test.cpp -o test -lstdc++ //必须加上 -lstdc++ 选项用来通知连接器连接静态库 libstdc++.a, //不然会由于找不到库函数而出错
g++ -Wall test.cpp -o test
该命令将文件‘test.cpp’中的代码编译为机器码并存储在可执行文件 ‘test’中。机器码的文件名是经过 -o 选项指定的,该选项一般做为命令行中的最后一个参数。若是被省略,输出文件默认为 ‘a.out’。 java
g++ test.cpp
本例中,编译器使用了 -Wall 选项而没产生任何警告,由于示例程序是彻底合法的。python
#include <stdio.h> int main(void) { printf("Hello, world!/n"); return 0; }
./test
hello, world
#include "test.h" int main() { test("hello world!"); return 0; }
void test(const char* name);
#include <iostream> using namespace std; #include "test.h" void test(const char* name) { cout<<"Hello World!"<<endl; }
g++ -Wall main.cpp test_fn.cpp -o newTest
CXXC=g++ CXXFLAGS=-Wall newTest: main.o test_fn.o //使用了隐含规则 cpp-->o clean: rm -f newTest main.o test_fn.o
$ make g++ -Wall -c -o main.o main.cpp g++ -Wall -c -o test_fn.o test_fn.cpp g++ main.o test_fn.o -o newTest 运行该可执行文件: $ ./newTest Hello, world!
$ vim test.cpp $ make //从新make g++ -Wall -c -o test.o test.c //此时只make该被修改的文件test.cpp g++ test.o test_fn.o -o newTest
$ ./newTest
Hello, world!
$ make clean
rm -f hello hello.o hello_fn.o
#include <math.h> #include <stdio.h> int main (void) { double x = sin (2.0); printf ("The value of sin(2.0) is %f/n", x); return 0; }
$ gcc -Wall calc.c -o calc /tmp/ccbR6Ojm.o: In function 'main': /tmp/ccbR6Ojm.o(.text+0x19): undefined reference to ‘sin’
$ gcc -Wall calc.c /usr/lib/libm.a -o calc
函数库‘libm.a’包含全部数学函数的目标文件,好比sin,cos,exp,log及sqrt。连接器将搜索全部文件来找到包含 sin 的目标文件。一旦包含 sin 的目标文件被找到,主程序就能被连接,一个完整的可执行文件就可生成了:
$ ./calc The value of sin(2.0) is 0.909297
$ gcc -Wall calc.c -lm -o calc
g++ test.cpp -std=c++11