tuple
c++の多次元のtuple(読み方: タプル)の扱いで苦労したので記載する。
今回はtupleのvectorで多次元タプルを使用。
以下プログラム。
#include <iostream> #include<vector> #include <string> #include <tuple> using namespace std; int main(void){ int n=5; int x[]={1,2,3,4,5}; int y[]={10,50,20,90,5}; string s="ABCDE"; vector <tuple<int,int,int>> p; for(int i=0;i<n;i++){ p.push_back(make_tuple(y[i],x[i],s[i])); } /* tupleの中身 (1,10,A) (2,50,B) (3,20,C) (4,90,D) (5,5,E) */ // 全要素表示 for( auto& element : p ) { cout << get<0>(element) << ", " << get<1>(element) << ", " << get<2>(element) << endl; } cout << endl; // 任意の要素を抽出 // 3番目の2番目の要素を変数に代入 int hoge= get<1>(p[3]); cout<< hoge <<endl; return 0; }
- タプルの表示
タプルの表示方法を2種類記載する。get<何番目の要素>(何番目のtuple)で記載する。
ここで<>の中には変数を入れることができないため、0,1,2...など直接数字を書く必要があるようだ。
// 全要素表示 for( auto& element : p ) { cout << get<0>(element) << ", " << get<1>(element) << ", " << get<2>(element) << endl; } cout << endl;
または
// 全要素表示 for(int i=0;i<n;i++){ cout<< get<0>(p[i])<<" "<< get<1>(p[i])<<" "<< get<2>(p[i]); cout<<endl; }
ちなみに実際に<>の中身を変数としてforで回す以下のプログラムが以下。
for(int i=0;i<n;i++){ for(int j=0;j<3;j++){ cout<< get<j>(p[i])<<" "; } cout<<endl; }
エラーが出る。
error: no matching function for call to 'get' cout<< get<k>(p[i])<<" "; ^~~~~~ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__tuple:226:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip' get(array<_Tp, _Size>&) _NOEXCEPT;
'auto' type specifier is a C++11 extension [-Wc++11-extensions]のエラー
以下のコンパイルエラーの対処法について
error: use of undeclared identifier 'tuple'
'auto' type specifier is a C++11 extension [-Wc++11-extensions]
[背景]
auto型やtupleをプログラム中で使用するときにコンパイルエラーが生じた。
コンパイルは以下のコマンドを使用。
c++ a.cpp
[理由]
autoとtupleはC++11で提供されるライブラリであるため、通常のコンパイルでは認識されない。
[対処法]
C++11の機能を有効化するオプションをつけることで解決。
c++ -std=c++11 a.cpp
batファイルを使って任意の名前のファイルとフォルダを作成する
背景
社内のレポート作成手順がめんどくさく、フォルダを作成し既にあるフォーマットファイルをその中にコピーして、そのファイル名をフォルダと同一にするという作業が必要だった。
めんどくさいのでフォルダ・ファイルの自動生成バッチを作成。
想定ファイル構成
- 実行前
./
|-Book1.xlsx
|-make_file.dat (作成バッチファイル)
- 実行後
./
|- Book1.xlsx
|-make_file.dat
|- new_name
|-new_name.xlsx
任意の名前を入力するとフォルダが作成される。さらにフォルダ内にBook1.xlsxがコピーされ、ファイル名がフォルダと同名になる。このプログラムを応用することで好きなファイル・フォルダ名でファイル構造を自動作成することができるかと思う。
実行方法
make_file.datをクリック
make_file.dat
〜 @ECHO OFF :INPUT_START ECHO +-------------------------------------------------------+ ECHO Please write file name ECHO +-------------------------------------------------------+ SET INPUT_STR= SET /P INPUT_STR= IF "%INPUT_STR%"=="" GOTO :INPUT_START REM 同名フォルダがない場合のみディレクトリ、ファイル作成 IF Exist .\%INPUT_STR% ( ECHO +-------------------------------------------------------+ ECHO "%INPUT_STR% is already exist" ECHO +-------------------------------------------------------+ ) IF NOT EXIST .\%INPUT_STR% ( MKDIR .\%INPUT_STR% COPY .\Book1.xlsx .\%INPUT_STR%\%INPUT_STR%.xlsx ECHO +-------------------------------------------------------+ ECHO file name to make is [%INPUT_STR%]. ECHO +-------------------------------------------------------+ ) PAUSE EXIT 〜
git memo
備忘録としてgitの使い方について記す。
git init
ローカルに新規gitリポジトリ作成。つまり.gitディレクトリを作成する。
git status
現在のgitの状態を表示する。
git add a.c
a.cファイルをローカルのリポジトリに追加する。gitの対象となるイメージ。
git commit -m "first commit"
addされているファイルの変更をリポジトリに記載する。.gitに書き込まれるイメージ。
オプション-mはコミットメッセージを追加できる。今回の例では”first commit”の部分。
git remote add origin https://github.com//awesome.git
gitを反映させるgithub上のレポジトリを登録する。originとしてurlを登録するイメージ。 git remote -v 登録したgithubのurlを確認できる。
git remote set-url origin {url}
{}は不要。githubのurlを変更する。
git push origin master
ローカルの.gitをgithubに反映。origin(githubレポジトリ)のmaster(ブランチ名)に反映。
よんでおきたい
http:// https://qiita.com/gold-kou/items/7f6a3b46e2781b0dd4a0
MACのルートディレクトリ配下のファイル
MAC book のディレクトリ構成がどうなってるのか調べた。
ディレクトリ | 正式名称 | 説明 |
---|---|---|
/Applications | 全ユーザのアプリケーションを管理 | |
/Users | users | 各ユーザのホームディレクトリを管理 |
/Library | 全ユーザのアプリケーションの設定を管理 | |
/Volumes | 外部記憶媒体に接続時のマウントポイントとなる | |
/System | システム設定やOSを管理 | |
/cores | カーネルのコアダンプを保存 | |
/bin | binary | コマンドラインの基本コマンドを管理 |
/dev | device | デバイスにアクセスするためのファイルを管理 |
/etc | etcetra | システム全体の設定ファイルを管理 |
/opt | option | インストールした静的データ(主にプログラム)を格納 |
/private | /var, /tmp, /etcの実体を管理 | |
/sbin | super user | システム管理用のコマンドを管理 |
/usr | user | ユーザが使用するコマンドやマニュアルが配置されている |
/tmp | temporaly | 一時保存のファイルを管理 |
/var | variation | システムのログファイルを管理 |
- /Application
appファイルが格納される。appファイルはアプリケーションのリソースファイルであり、実行時に参照される。
Android Emulator.app/ GitHub Desktop.app/ Pages.app/ Utilities/ Android Studio.app/ Keynote.app/ Safari.app/ Kindle.app/ ShiftIt.app/ Visual Studio Code.app/ Docker.app/ Microsoft Teams.app/ Unity/ feedly.app/ GarageBand.app/ Numbers.app/ Unity Hub.app/ iMovie.app/
- /Users
各ユーザの名前のディレクトリが格納される。
Shared/ Taro/ Jhon/
- Library
アプリケーションの設定を行なったデータを保存する。MAC中にライブラリは3つ存在し、ルートディレクトリ直下のこのライブラリでは全ユーザアカウントで共有する設定データを格納。
Apple/ DirectoryServices/ Java/ Preferences/ StagedDriverExtensions/
Application Support/ Documentation/ KernelCollections/ Printers/ StagedExtensions/
Audio/ DriverExtensions/ Keyboard Layouts/ Python/ StartupItems/
Caches/ Extensions/ Keychains/ QuickLook/ SystemExtensions/
Catacomb/ Filesystems/ LaunchAgents/ Receipts/ SystemMigration/
ColorPickers/ Fonts/ LaunchDaemons/ Ruby/ SystemProfiler/
ColorSync/ Frameworks/ Logs/ Sandbox/ Updates/
Components/ GPUBundles/ Managed Preferences/ Screen Savers/ User Pictures/
Compositions/ Graphics/ Modem Scripts/ ScriptingAdditions/ User Template/
Contextual Menu Items/ Image Capture/ OSAnalytics/ Scripts/ Video/
CoreAnalytics/ Input Methods/ OpenDirectory/ Security/ WebServer/
CoreMediaIO/ InstallerSandboxes/ Perl/ Speech/
Developer/ Internet Plug-Ins/ PreferencePanes/ Spotlight/
- Volumes
接続している外部記憶装置の名前のディレクトリを格納。Macintosh HDはMACのこと、NO NAMEは刺しているUSBメモリである。
Macintosh HD@/ NO NAME/ Recovery/
- System
システム設定を格納。
Applications/ DriverKit/ Volumes/ Developer/ Library/ iOSSupport/
- cores
lsしても中身はなし。
- bin
[* dash* expr* ln* pwd* sync* bash* date* hostname* ls* rm* tcsh* cat* dd* kill* mkdir* rmdir* test* chmod* df* ksh* mv* sh* unlink* cp* echo* launchctl* pax* sleep* wait4path* csh* ed* link* ps* stty* zsh*
- /dev
多数ファイルあり。
- /etc
/etc@
- /opt
cisco/ homebrew/
- /private
etc/ tftpboot/ tmp/ var/
- /sbin
apfs_hfs_convert@ fstyp_msdos* mount_cddafs@ newfs_hfs@ apfs_unlockfv* fstyp_ntfs* mount_devfs* newfs_msdos@ disklabel* fstyp_udf* mount_exfat@ newfs_udf@ dmesg* halt* mount_fdesc* nfsd* dynamic_pager* ifconfig* mount_ftp@ nfsiod* emond* kextload* mount_hfs@ nologin* fibreconfig* kextunload* mount_msdos@ pfctl* fsck* launchd* mount_nfs* ping* fsck_apfs@ md5* mount_ntfs@ ping6* fsck_cs* mknod* mount_smbfs* quotacheck* fsck_exfat@ mount* mount_tmpfs@ reboot* fsck_hfs@ mount_9p* mount_udf@ route* fsck_msdos@ mount_acfs@ mount_webdav* rtsol* fsck_udf@ mount_afp* mpioutil* shutdown* fstyp* mount_apfs@ newfs_apfs@ umount* fstyp_hfs* mount_cd9660@ newfs_exfat@
- /usr
X11@ bin/ libexec/ sbin/ standalone/ X11R6@ lib/ local/ share/
- /tmp
tmp@
- /var
var@
M1 MACの開発環境セットアップメモ
-
homebrew
sudo mkdir /opt/homebrew
chown ${USER}$:admin homebrew
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C /opt/homebrew
パスを通す
export PATH=/opt/homebrew/bin:$PATH
アンインストール
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
mac m1に対応済みのよう。
-
docker
通常のdocker for desktopはapple siliconeに対応していないため、docker previewをダウンロードする。
Apple M1 Tech Preview | Docker Documentation
Visual Studio Code - Code Editing. Redefined
こちらのサイトよりdownload for Macでダウンロードできる。
pythonのpipについて
import package-name
この時,pipを更新してからパッケージをインストールする必要がある.
pipの更新
pip -m pip install --upgrade pip
パッケージのインストール(package-name=任意のパッケージ名)
pip install package-name
インストールしたパッケージのリストを見る
pip list