時間:2023-07-27 14:21:01 | 來源:網(wǎng)站運營
時間:2023-07-27 14:21:01 來源:網(wǎng)站運營
在手機上使用termux寫C++代碼并編譯運行:本文將會介紹如何使用termux寫C++代碼并編譯運行。sed -i 's@^/(deb.*stable main/)$@#/1/ndeb https://mirrors.tuna.tsinghua.edu.cn/termux stable main@' $PREFIX/etc/apt/sources.list相關(guān)幫助鏈接:https://mirror.tuna.tsinghua.edu.cn/help/termux/
sed -i 's@^/(deb.*stable main/)$@#/1/ndeb https://mirrors.ustc.edu.cn/termux stable main@' $PREFIX/etc/apt/sources.list相關(guān)幫助鏈接:http://mirrors.ustc.edu.cn/help/termux.html
apt clean如國內(nèi)鏡像源出現(xiàn)問題、出現(xiàn)錯誤或不能下載到想要的軟件,可以換回官方鏡像源:
pkg up
sed -i 's@^/(deb.*stable main/)$@#/1/ndeb https://termux.net/ stable main@' $PREFIX/etc/apt/sources.list當無法連接官方鏡像源時應(yīng)科學(xué)上網(wǎng)再次嘗試。
cd <目錄地址> 打開目錄地址更多命令請自行搜索相關(guān)資料。
cp <文件名> <目標目錄地址> 拷貝到目標目錄地址
mkdir <文件夾名> 新建文件夾
rm <文件名> 刪除文件
rm -rf <文件夾名> 刪除文件夾
ls 查詢該文件夾下文件及文件夾
pkg install vim clang python gdb cgdb curl
i 切換到編輯模式更多命令請自行搜索相關(guān)資料。
ESC 退出編輯模式
:x 保存退出
:q 未改動退出
:q! 不保存退出
g++ <cpp代碼文件> -o <生成程序名>如:
g++ hello.cpp -o hello即可在該目錄下生成名為hello的可執(zhí)行文件。
./<可執(zhí)行文件名>如:
./hello即可執(zhí)行hello程序。
chmod -x <程序名>如:
chmod -x hello即可執(zhí)行。
vim ~/.vimrc將下面大括號內(nèi)部內(nèi)容復(fù)制粘貼進去保存即可。
" 設(shè)置當文件被改動時自動載入}
set autoread
" quickfix模式
autocmd FileType c,cpp map <buffer> <leader><space> :w<cr>:make<cr>
"代碼補全
set completeopt=preview,menu
"允許插件
filetype plugin on
"共享剪貼板
set clipboard=unnamed
"從不備份
set nobackup
"自動保存
set autowrite
set ruler " 打開狀態(tài)欄標尺
set cursorline " 突出顯示當前行
set magic " 設(shè)置魔術(shù)
set guioptions-=T " 隱藏工具欄
set guioptions-=m " 隱藏菜單欄
set foldcolumn=0
set foldmethod=indent
set foldlevel=3
set foldenable " 開始折疊
" 不要使用vi的鍵盤模式,而是vim自己的
set nocompatible
" 語法高亮
set syntax=on
" 去掉輸入錯誤的提示聲音
set noeb
" 在處理未保存或只讀文件的時候,彈出確認
set confirm
" 自動縮進
set autoindent
set cindent
" Tab鍵的寬度
set tabstop=4
" 統(tǒng)一縮進為4
set softtabstop=4
set shiftwidth=4
" 不要用空格代替制表符
set noexpandtab
" 在行和段開始處使用制表符
set smarttab
" 顯示行號
set number
" 歷史記錄數(shù)
set history=1000
"禁止生成臨時文件
set nobackup
set noswapfile
"搜索忽略大小寫
set ignorecase
"搜索逐字符高亮
set hlsearch
set incsearch
"行內(nèi)替換
set gdefault
"編碼設(shè)置
set enc=utf-8
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
"語言設(shè)置
set langmenu=zh_CN.UTF-8
set helplang=cn
" 我的狀態(tài)行顯示的內(nèi)容(包括文件類型和解碼)
set statusline=[%F]%y%r%m%*%=[Line:%l/%L,Column:%c][%p%%]
" 總是顯示狀態(tài)行
set laststatus=2
" 命令行(在狀態(tài)行下)的高度,默認為1,這里是2
set cmdheight=2
" 偵測文件類型
filetype on
" 載入文件類型插件
filetype plugin on
" 為特定文件類型載入相關(guān)縮進文件
filetype indent on
" 保存全局變量
set viminfo+=!
" 帶有如下符號的單詞不要被換行分割
set iskeyword+=_,$,@,%,#,-
" 字符間插入的像素行數(shù)目
set linespace=0
" 增強模式中的命令行自動完成操作
set wildmenu
" 使回格鍵(backspace)正常處理indent, eol, start等
set backspace=2
" 允許backspace和光標鍵跨越行邊界
set whichwrap+=<,>,h,l
" 可以在buffer的任何地方使用鼠標(類似office中在工作區(qū)雙擊鼠標定位)
set mouse=a
set selection=exclusive
set selectmode=mouse,key
" 通過使用: commands命令,告訴我們文件的哪一行被改變過
set report=0
" 高亮顯示匹配的括號
set showmatch
" 匹配括號高亮的時間(單位是十分之一秒)
set matchtime=1
" 光標移動到buffer的頂部和底部時保持3行距離
set scrolloff=3
" 為C程序提供自動縮進
set smartindent
" 高亮顯示普通txt文件(需要txt.vim腳本)
au BufRead,BufNewFile * setfiletype txt
"自動補全
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {<CR>}<ESC>O
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "/<Right>"
else
return a:char
endif
endfunction
filetype plugin indent on
"打開文件類型檢測, 加了這句才可以用智能補全
set completeopt=longest,menu
"C++的編譯和運行
"編譯運行
map <F10> :call CompileRunGpp()<CR>
func! CompileRunGpp()
exec "w"
exec "!g++ % -o %<"
exec "! ./%<"
endfunc
"編譯
map <F8> :call CompileGpp()<cr>
func! CompileGpp()
exec "w"
exec "!g++ % -o %<"
endfunc
"運行
map <F9> :call RunGpp()<cr>
func! RunGpp()
exec "w"
exec "! ./%<"
endfunc
F8(音量+鍵 + 8) 編譯
F9(音量+鍵 + 9) 運行
F10(音量+鍵 + 0) 編譯并運行
sh -c "$(curl -fsSL https://github.com/Cabbagec/termux-ohmyzsh/raw/master/install.sh)"Android 6.0以上可能會彈框確認是否授權(quán)訪問文件,點擊允許,之后會在termux根目錄生成storage目錄,可以方便地對外部文件進行操作。
Enter a number, leave blank to not to change:我選的是14和6,僅供參考。
Enter a number, leave blank to not to change:
~/termux-ohmyzsh/install.sh重啟軟件或開啟新session生效。
vim $PREFIX/etc/motd保存重啟即可。
pkg install nyancat
nyancat
關(guān)鍵詞:編譯,運行,使用
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。