Undergraduate
情報

【プログラミング入門】#2 操作方法とコマンド操作

11

415

0

たくのろじぃ

たくのろじぃ

プログラミングと書いておいてまだプログラミングしません。
どうしてもコマンド操作が必要なので、コマンド操作に慣れてしまおうという回です。
このスライドは実際に友人と操作しながら使っていたので、ちょっと分かりにくいところがあるかもしれません。

PromotionBanner

ノートテキスト

ページ1:

OCR失敗: NoMethodError undefined method `first' for nil:NilClass

ページ2:

前回やったこと
•
Visual Studio Code のインストール
•
MinGW のインストール
•
gcc バージョンの確認
具体的な内容は前回のスライドを参照してください

ページ3:

今回やること
1. Visual Studio Code の拡張機能インストール
2.Cファイルの作成
3. CLI (ターミナル) の操作方法
プログラミングは次回からです。 今回は必要な操作方法についてです。
キーワード:
Visual Studio Code (VS Code), エディタ, 拡張機能, 拡張子(.c), CLI,
ターミナル, GUI, cd, Is, clear, ディレクトリ, カレントディレクトリ, ルートディレクトリ

ページ4:

89
1. Visual Studio Code (VS Code)
プログラムを書くのに最適なソースコードエディタ
拡張機能を導入すると、 様々な言語に対応したサポートを受けれる
File Edit Selection View
Go Debug Terminal Help
Extension: C/C++. Visual Studio Code
Extension C/C++ X
EXTENSIONS MARKETPLACE
C/C++ ms-vscode.cpptools
Microsoft 8,704.101 ★★★☆☆
Repository Lice
License
CCC/C++ IntelliSense, debugging, and c...
C/C++ C/C++ IntelliSense, debugging, and code browsing.
C/C++ 0.242
Microsoft
Uninstalled Instal
C/C++ Clang Co... 0230*45
Completion and Diagnostic for C/C+
YMITANI
CF 1219
Install is recommended based on the files you recently opened ignore Recommendation
C# for Visual Studio Code (powered.
Microsoft
Details Contributions Channele
Compile & Run single c/c++ files easly
danielpinto
C/C++ for Visual Studio Code
C/C
Snippets 00.14
Code snippets for C/C++
Harsh
Debugger for Chr... 4123 484 4
Debug your JavaScript code in the C...
Microsoft
Prettier Code f... 1.10 4 15
Code formatter using prettier
Esben Petersen
C/C++ GNU Global 0.32
CC Intellisense for C/C++ using GNU GL..
Lin Chich
C Compiler..
Compile and execute C files from VS...
Code Runner 09
.run Run C, C++, Java, JS, PHP, Python, Pe
Update to 0.9.15
Jun Han
O
Chinese (Simplifie... 1412 @15 *5
中文 (体)
Microsoft
Monkey C 0.3.1
Repository | Issues | Documentation | Code Samples | Offline Installers
Live Share enabled
This preview release of the C/C++ extension adds language support for C/C++ to Visual Studio Code, including features such as
IntelliSense and debugging.
Overview and getting started
• C/C++ extension overview
Get Started with C++ and Windows Subsystem for Linux (WSL)
Get Started with C++ and Ming-w64
Get Started with C++ and Clang/LLVM on macos
Get Started with C++ and Microsoft C++ compiler (MSVC)
Quick links
Editing features (IntelliSense)
IntelliSense configuration
Enhanced colorization
Debugging
Debug configuration
早速、 拡張機能を入れてみましょう!
1. ブロックみたいなタブをクリック
2. 検索欄にCと入力
3. C/C++ をクリック
4. Install をクリック
これでC言語をサポートしてくれます!
T

ページ5:

2. C言語ファイルの作成 (1)
File Edit Selection View Go Debug
minal Help
Untitled-1- Visual Studio Code
New File
Ctrl+N
Extension: C/C++
Untitled-1 X
New Window
Ctrl+Shift+N
1
Open File...
Ctrl+0
Open Folder...
Ctrl+KCtrl+O
Open Workspace...
Open Recent
Add Folder to Winrksnare
File > New File をクリック
新規ファイルが作られるので、ここで [Ctrl] + [s] キーを押す

ページ6:

2. C言語ファイルの作成(2)
Save As
This PC > Data Disk3 (F:) > C
Organize ▼
New folder
Music
Pictures
Name
Videos
Windows 10 (C:)
Data Disk1 (D:)
Data Disk 2 (E:)
Date modified
Type
No items match your search.
Size
Search C
Data Disk3 (F:)
Windows Server
Libraries
Documents
「ファイル名.c」とする (拡張子をc にする)
Music
Pictures
Videos
File name Test.c
Save as type: Plain Text (".txt;*.gitignore)
へ Hide Folders
できたら好きな場所に保存
Save
Cancel

ページ7:

2. C言語ファイルの作成(3)
minal Help
≡ Extension: C/C++
Test.c Visual Studio Code
C Test.c
F: > C > C Test.c
1
アイコン(赤枠内)がCになっていれば作成OK

ページ8:

3. CLI (ターミナル) の操作方法
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://as/scoreb
PS C:\Users\takunis
Directory: Cersitalum
Hode
Last TriteTime
Length Nase
AndroidStudio30
Box
cache
cont
laver
eclipse
-in-2-8
°
CLI (Command Line Interface)
コンピュータに対してコマンドを打つことで操作する方法
Linux や Mac では “ターミナル” と言うことがある
コマンドを知らないと使えないが、システム内部の操作ができる
例) コマンドプロンプト、 PowerShell、 ターミナルなど・・・・
ページレイアウト
nedegre
woanishare
Cylind
購入
***
$ % テーブルとして
Ex
F
-P
アイケア NEW
GUI (Graphical User Interface)
マウスやタッチパネルなどを使って操作する方法
昔はCLIしかなかったが、 現在のPCはほぼGUIで何でもできる
誰でも使えるが、 クリックできるような場所しか操作できない
例) Office系ソフト、Webブラウザ、ペイント、 メモ帳 など・・・

ページ9:

3.1 VS Code のターミナルを開く
File
Edit Selection View Go Debug Terminal Help
Test.c - Vi
TERMINAL
1: powershell
+
X
EXPLORER
Command Palette...
Ctrl+Shift+P
C++
Active code page: 65001
OPEN EDITORS
Open View...
.C
PS C:\Users\takun>
Extension: C/
Appearance
XC Test.c F:\C
Editor Layout
>
✓ NO FOLDER OPENED
Explorer
Ctrl+Shift+E
You have not yet o
Search
Ctrl+Shift+F
O
SCM
Ctrl+Shift+G
Debug
Ctrl+Shift+D
Extensions
Ctrl+Shift+X
Output
Ctrl+Shift+U
Ln 1, Col 1 Spaces: 4 UTF-8 CRLF
Win32
D
Debug Console
Ctrl+Shift+Y
Terminal
Ctrl+@
Problems
Ctrl+Shift+M
Toggle Word Wrap
Alt+Z
VS Code の右下にこのような画面が
出ていればターミナルが起動しています!
Co
Show Minimap
View Terminal

ページ10:

3.2 ディレクトリの移動
ディレクトリ (Directory) ・・・ ファイルが保存されている階層 (場所)
Windowsで言う「フォルダー」のこと
最初はユーザのディレクトリが指定されている (C:\User\ユーザ名)
階層移動するためのコマンド:cd
cd の後ろに半角スペースを空けて、移動したい階層を指定する
cd は change directory の略で、 ディレクトリ変更の意味がある

ページ11:

3.2 ディレクトリの移動コマンド (1)
TERMINAL
PS C:\Users\takun> cd..
PS C:\Users>
1: powershell
TERMINAL
PS C:\Users> cd Public
PS C:\Users\Public> |
1: powershell
1つ上の階層へ移動
cd..
Users の階層へ
指定した1つ下の階層へ移動
cd ディレクトリ名
Public の階層へ

ページ12:

3.2 ディレクトリの移動コマンド (2)
任意の階層に行きたいときは、その階層を指定しても移動できる
ID DIC
File
Home
Share
Move to X Delete
M
Pinto Quick Copy Pastel
Copy to
Rename
New
access
回
folder
Clipboard
Organize
New
Undo
↓ Downloads オヘ
Name
Cut
Documents
Hello.c
Copy
Pictures
Img.c
Paste
MISIA
C Test.c
Delete
iCloud Photo
Select All
iCloud Drive
OneDrive
■ This PC
■3D Objects
■ Desktop
Select all
D
Select none
Properties
e
品 Invert selecti
TERMINAL
Open
Select
Search C
Right to left Reading order
Show Unicode control characters
Insert Unicode control character
>
Close IME
Reconversion
Documents
Downloads
移動したい階層までのパスをコピー
PS C:\Users> cd Public
1: powershell
PS C:\Users\Public > cd F:\C
PS F:\C>
指定した階層へ移動
cd フルパス
[Ctrl] + [c]: コピー
[Ctrl] + [v] : ペースト

ページ13:

3.3 ディレクトリ内のファイルを確認する
移動したい階層があっても、 どんなファイルやディレクトリがあるか分からない
→ Is コマンドを使って確認してみよう
PS C:\Users\takun> cd F:\C
PS F:\C> 1s
Directory: F:\C
Mode
LastWriteTime
12/6/2019
12/26/2018
12/27/2019
2:00AM
1:35 AM
6:31 PM
PS F:\C>
Length Name
68 Hello.c
510 Img.c
F:\C
S⭑
Name
ts
CHello.c
© Img.c
CTest.c
e Test.c
oto✰
CLI と GUI で同じファイル名を見ることができる
Is は list の略で、そのディレクトリのファイルリストを表示する意味がある

ページ14:

3.4 ディレクトリの作成
新しくディレクトリを作成する場合は mkdir コマンドを使う
例)mkdir TEST というコマンドを実行すると、 TESTディレクトリができる。
PS F:\C> mkdir TEST
Mode
Directory: F:\C
d-----
LastWriteTime
Length Name
12/27/2019 7:32PM
TEST
PS F:\C> cd TEST
PS F:\C\TEST>
mkdir は make directory の略で、その階層で新しいディレクトリを作成することを意味する

ページ15:

3.5 ディレクトリの削除
ディレクトリを削除する場合は rmdir コマンドを使う
例)rmdir TEST というコマンドを実行すると、 TESTディレクトリが削除される
PS F:\C\TEST > cd ..
PS F:\C> rmdir TEST
PS F:\C> 1s
Directory: F:\C
Mode
LastWriteTime
Length Name
12/6/2019
12/26/2018
2:00 AM
68 Hello.c
1:35 AM
510 Img.c
12/27/2019
6:31PM
0 Test.c
PS F:\C>
rmdir は remove directory の略で、指定したディレクトリを削除することを意味する

ページ16:

3.6 画面上の文字を消す
コマンドを使用していると、画面が文字で埋め尽くされてしまう
→ clear コマンドを実行して画面上の文字を消す
PROBLEMS TERMINAL
1: powershell
12/6/2019 2:00AM
12/26/2018 1:35AM
12/27/2019 6:31PM
+ 11
PROBLEMS
TERMINAL
1: powershell
+
11
68 Hello.c
510 Img.c
PS F:\C>
0 Test.c
PS F:\C> 1s
Mode
Directory: F:\C
PS F:\C>
LastWriteTime
12/6/2019 2:00AM
12/26/2018 1:35 AM
12/27/2019
6:31PM
Length Name
68 Hello.c
510 Img.c
e Test.c
※完全に消えるわけではなく、見ている範囲のみ消してくれます。 上にスクロールすればまた出てきます

ページ17:

3.7 補足
•
ルートディレクトリ (root directory)
最初に起動したときにいるディレクトリ。 (Linuxでは1番上の階層を意味する)
コマンド cd ~
カレントディレクトリ (current directory)
現在いるディレクトリのこと。ファイル作成やコンパイルはカレントディレクトリで行う
カレントディレクトリの階層を知りたいときのコマンド:pwd
コマンド履歴
ターミナル上で[↑]キーを押すと、今までに打ってきたコマンドが出てくる
.
入力補完
ターミナル上で [tab]キーを押すと、コマンドを補完してくれる(結構楽できる)
•
Is コマンドのオプション
Is ディレクトリ名で、そのディレクトリ内のファイル一覧を見ることができる

ページ18:

まとめ
•
VS Code の拡張機能を導入
.
C形式のファイルを作成
• ディレクトリについてと、ターミナルの使用方法
•
各種コマンドについてと補足

留言

尚未有留言

News