includeはコピペしたり他に何かやろうとした時のやつがそのままなので適当
2進数変換
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
#include <iostream> #include <bitset> int main() { int lol{ 0b00001000 }; int www{ 0b00000011 }; std::bitset<8> b1(lol); std::bitset<8> b2(www); std::bitset<8> b3(0b00000000); for (;;) { b3 = b1 & b2; if (b3.any()) { b3 = b3 << 1; b1 = b1 ^ b2; b2 = b3; } else { b3 = b1 ^ b2; break; } } std::cout << "lol = " << lol << std::endl; std::cout << "www = " << www << std::endl; std::cout << "10進数答え = " << lol + www << std::endl; std::cout << "2進数答え = " << b3 << std::endl; } |
base_for
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
#include <iostream> struct back_and_forth { struct iterator { int operator* () const { return n; } iterator& operator++() { ++n; return *this; } bool operator==(const iterator& r) const { return n == r.n; } bool operator!=(const iterator& r) const { return !operator==(r); } int n; }; int front; int back; iterator begin() const { return { front }; } iterator end() const { return { back + 1 }; } }; int main() { for (const auto x : back_and_forth{ 0,9 }) { std::cout << x; } //for (int i = 0; i <= 19; ++i) //std::cout << (i <= 9 ? i : 19 - i); } |
bit_con_shift_2_4_8
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#include <iostream> #include <stdio.h> #include <vector> #include <wchar.h> #include <string> #include <vector> #include <bitset> #include <thread> #include <chrono> int main() //intのbit変換、10進数を左にシフトすると2倍4倍8倍16倍になる右にシフトは逆 { int aaa{ 4 }; int sss{ ~0x2 }; //sss = aaa << 1; std::cout << aaa << std::endl; std::cout << sss << std::endl; std::bitset<8> bit1(aaa); std::bitset<8> bit2(sss); std::cout << bit1 << std::endl; std::cout << bit2 << std::endl; std::this_thread::sleep_for(std::chrono::seconds(3)); std::cout << ~0x2 << std::endl; } |
boolに評価
|
1 2 3 4 5 6 7 8 9 10 |
#include <iostream> int main() { int a = 1; bool b = (a > 0); if (b) { std::cout << "aaa" << std::endl; } } |
cout関数、演算子オーバーロード
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
#include <iostream> struct AAA { int n; int m; std::istream& read_from(std::istream& iii) { return iii >> n >> m; } std::ostream& write_to(std::ostream& ooo) { return ooo << n << ' ' << m; } }; std::istream& operator>> (std::istream& iii, AAA& r) { return r.read_from(iii); } std::ostream& operator<< (std::ostream& ooo, AAA& r) { return r.write_to(ooo); } int main() { AAA x; if (std::cin >> x) //別の書き方だと if(operator>>(std::cin, x) 普通の関数の呼び出し、これと同義 { std::cout << x << std::endl; } } |
node
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#include <iostream> #include <stdio.h> #include <vector> #include <wchar.h> #include <string> #include <vector> #include <bitset> struct node { char s[256]; struct node* aaa; }; int main() { struct node node4 = { "you?", NULL }; struct node node3 = { "are", &node4 }; struct node node2 = { "How", &node3 }; struct node node1 = { "Hi!", &node2 }; struct node* Head = &node1; struct node* p = Head; do { printf("%s\n", p->s); p = p->aaa; } while (p != NULL); } |
ostringatream
|
1 2 3 4 5 6 7 8 9 10 |
#include <iostream> #include <sstream> int main() { int a = 1; int b = 1; std::ostringstream ddd; ddd << "あああ"; std::cout << ddd.str() << std::endl; } |
pointer_function
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
#define _CRTDBG_MAP_ALLOC #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <stdio.h> #include <vector> #include <wchar.h> #include <string> #include <vector> #include <bitset> #include <malloc.h> void stateA() { std::cout << "State A" << std::endl; } void stateB() { std::cout << "State B" << std::endl; } void stateC() { std::cout << "State C" << std::endl; } int main(void) { // 関数テーブル void (*stateTable[])() = { stateA, stateB, stateC }; // 遷移テーブル int transitionTable[3][3] = { {1, 2, 2}, // 状態Aから遷移 {0, 2, 0}, // 状態Bから遷移 {0, 1, 1} // 状態Cから遷移 }; int currentState = 0; for (int i = 0; i < 10; i++) { // 現状の関数を実行する (*stateTable[currentState])(); // 次の状態へ移行する currentState = transitionTable[currentState][i % 3]; } return 0; } |
reverse_out
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#include <iostream> #include <stdio.h> #include <vector> #include <wchar.h> #include <string> #include <vector> int main() //配列の逆順出力 { std::wcout.imbue(std::locale("Japanese")); int aaa[]{ 1,2,3,4,5 }; for (int i = sizeof aaa / sizeof * aaa -1;; i--) if (i < 0) { break; } else { std::cout << aaa[i] << std::endl; } return 0; } |
staticで変数保持
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include <iostream> class aaa { static int a; public: aaa() { ++a; } ~aaa() { --a; } static void Disp() { std::cout << a << std::endl; } }; int aaa::a; int main() { aaa::Disp(); aaa a, b, c; aaa::Disp(); return 0; } |
struct_variable
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include <iostream> #include <stdio.h> #include <vector> #include <wchar.h> #include <string> #include <vector> #include <bitset> struct Lol { char name[25]; int atk; int def; }; int main(void) { const Lol aaa[] = { { "コッコ隊長", 245, 255 }, { "コッコ副隊長", 140, 100 }, { "コッコ隊員A", 0, 10 }, { "コッコ隊員B", 15, 5 }, { "コッコ隊員C", 5, 15 } }; int n = sizeof aaa / sizeof Lol; int i; for (i = 0; i < n; i++) { std::cout << aaa[i].name << " " << aaa[i].atk << " " << aaa[i].def << std::endl; } return 0; } |
unique_ptr
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include <memory> #include <vector> #include <iostream> class aaa { public: int q; aaa() : q(8) { } ~aaa() { std::cout << __FUNCSIG__ << std::endl; } }; int main() { std::unique_ptr<aaa> sss(new aaa); std::cout << sss->q << std::endl; } |
vectorイテレータ
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include <iostream> #include <stdio.h> #include <vector> #include <wchar.h> #include <string> #include <vector> #include <bitset> int main() { std::vector<int> a{ 1,2,3,4,5 }; auto it = a.begin(); for (int i = 0; i < 4; ++i, ++it) { std::cout << i << "::" << *it << std::endl; } } |
インターフェイス
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include <iostream> #define IDD 111 //参照値未設定 struct aaa { virtual void lol(int* a) = 0; virtual void kaiho() = 0; }; struct bbb :public aaa { int* p; void lol(int* a) override { *p += *a; } void kaiho() override { delete this; } }; void* CreA(int iid) { if (IDD == iid) { return new bbb(); } return NULL; } int main() { { int a = 11; bbb* obj = (bbb*)CreA(IDD); obj->p = &a; std::cout << *(obj->p) << std::endl; } int a = 11; bbb* obj = (bbb*)CreA(IDD); obj->p = &a; std::cout << *(obj->p) << std::endl; } |
キャスト
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include <iostream> int main() { int a = 123; double b = 7.1; int* q = &a; double* w = &b; std::cout << *q << std::endl; std::cout << *w << std::endl; w = reinterpret_cast<double*>(q); std::cout << *q << std::endl; std::cout << *w << std::endl; } |
クラス
|
1 2 3 4 5 6 7 |
#include "クラスのヘッダ.h" int main() { aaa s; s.t(); } |
|
1 2 3 4 5 6 7 |
#include "クラスのヘッダ.h" int main() { aaa s; s.t(); } |
ヘッダ
|
1 2 3 4 5 6 7 8 9 10 |
#pragma once #include <iostream> class aaa { static const int a{ 3 }; void f(); public: void t(); }; |
スタック
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include <iostream> #include <stdio.h> #include <vector> #include <wchar.h> #include <string> #include <vector> void push(int S[], int value) { S[--S[0]] = value; } int pop(int S[]) { return S[S[0]++]; } int main() { int S[8]; S[0] = 8; push(S, 8); push(S, 4); push(S, 1); push(S, 3); pop(S); pop(S); push(S, 2); pop(S); } |
バインド
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include <iostream> #include <functional> int main() //bindはラムダ式より遅い { auto aaa = [](int x, int y) { std::cout << x << ":" << y << std::endl; }; auto bbb = std::bind(aaa, 1, 2); bbb(); auto ccc = [](int x, int y) { std::cout << x << ":" << y << std::endl; }; auto ddd = std::bind(ccc, std::placeholders::_2, std::placeholders::_1); //ホルダーは未設定の値の入れ物 _1の部分で入れ替え可能 ddd(10, 20); auto eee = [](int x, int y) { std::cout << x << ":" << y << std::endl; }; auto fff = std::bind_front(aaa, 1); //フロントは前から【指定しただけの引数】を固定する。つまり通常バインドと同じく全固定可能 fff(3); } |
フック
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
#include <stdio.h> #include <windows.h> #include <imagehlp.h> #pragma comment(lib,"imagehlp.lib") void* RewriteFunctionImp(const char* szRewriteModuleName, const char* szRewriteFunctionName, void* pRewriteFunctionPointer) { for (int i = 0; i < 2; i++) { // ベースアドレス DWORD dwBase = 0; if (i == 0) { if (szRewriteModuleName) { dwBase = (DWORD)(intptr_t)::GetModuleHandleA(szRewriteModuleName); } } else if (i == 1) { dwBase = (DWORD)(intptr_t)GetModuleHandle(NULL); } if (!dwBase)continue; // イメージ列挙 ULONG ulSize; PIMAGE_IMPORT_DESCRIPTOR pImgDesc = (PIMAGE_IMPORT_DESCRIPTOR)ImageDirectoryEntryToData((HMODULE)(intptr_t)dwBase, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ulSize); for (; pImgDesc->Name; pImgDesc++) { const char* szModuleName = (char*)(intptr_t)(dwBase + pImgDesc->Name); // THUNK情報 PIMAGE_THUNK_DATA pFirstThunk = (PIMAGE_THUNK_DATA)(intptr_t)(dwBase + pImgDesc->FirstThunk); PIMAGE_THUNK_DATA pOrgFirstThunk = (PIMAGE_THUNK_DATA)(intptr_t)(dwBase + pImgDesc->OriginalFirstThunk); // 関数列挙 for (; pFirstThunk->u1.Function; pFirstThunk++, pOrgFirstThunk++) { if (IMAGE_SNAP_BY_ORDINAL(pOrgFirstThunk->u1.Ordinal))continue; PIMAGE_IMPORT_BY_NAME pImportName = (PIMAGE_IMPORT_BY_NAME)(intptr_t)(dwBase + (DWORD)pOrgFirstThunk->u1.AddressOfData); if (!szRewriteFunctionName) { // 表示のみ printf("Module:%s Hint:%d, Name:%s\n", szModuleName, pImportName->Hint, pImportName->Name); } else { // 書き換え判定 if (stricmp((const char*)pImportName->Name, szRewriteFunctionName) != 0)continue; // 保護状態変更 DWORD dwOldProtect; if (!VirtualProtect(&pFirstThunk->u1.Function, sizeof(pFirstThunk->u1.Function), PAGE_READWRITE, &dwOldProtect)) return NULL; // エラー // 書き換え void* pOrgFunc = (void*)(intptr_t)pFirstThunk->u1.Function; // 元のアドレスを保存しておく WriteProcessMemory(GetCurrentProcess(), &pFirstThunk->u1.Function, &pRewriteFunctionPointer, sizeof(pFirstThunk->u1.Function), NULL); pFirstThunk->u1.Function = (DWORD)(intptr_t)pRewriteFunctionPointer; // 保護状態戻し VirtualProtect(&pFirstThunk->u1.Function, sizeof(pFirstThunk->u1.Function), dwOldProtect, &dwOldProtect); return pOrgFunc; // 元のアドレスを返す } } } } return NULL; } void* RewriteFunction(const char* szRewriteModuleName, const char* szRewriteFunctionName, void* pRewriteFunctionPointer) { return RewriteFunctionImp(szRewriteModuleName, szRewriteFunctionName, pRewriteFunctionPointer); } void PrintFunctions() { printf("----\n"); RewriteFunctionImp(NULL, NULL, NULL); printf("----\n"); } |
ポインタ引数char
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include <iostream> void f1(const char& a) { std::cout << a << std::endl; } void f2(const char** a) { std::cout << *a << std::endl; } int main() { const char* s = "lol"; const char w[] = "pkk"; f1(*w); f1(*s); f2(&s); } |
ポインタ配列引数int
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include <iostream> void f(int **a) { std::cout << a << "::" << *a << "::" << **a << std::endl; } int main() { int a = { 123 }; int b = { 234 }; int c = { 345 }; int* s[] = { &a,&b,&c }; f(s); } |
マップ
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include <unordered_map> #include <iostream> #include <string> template<typename Map> int on_map() { Map map = { { 2, "arikitari" }, { 7, "na" }, { 51, "sekai" }, { 21, "arikitari" }, { 73, "na" }, { 63, "sekai" }, { 13, "arikitari" }, { 27, "na" }, { 12, "sekai" }, }; auto it = map.begin(); for (int i = 0; i < 3; ++i, ++it) { std::cout << it->first << ',' << it->second << std::endl; } std::cout << map[55] << std::endl; for (; it != map.end(); ++it) { std::cout << it->first << ',' << it->second << std::endl; } return 0; } int main() { on_map<std::unordered_map<int, std::string>>(); std::cout << "-----------" << std::endl; } |
メンバとリテラルのポインタ
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#include <iostream> struct aaa { int s; int d; }; int main() { aaa z, r, h; int* p = &z.d; *p = 123; //int のポインタ int aaa::* o = &aaa::d; z.*o = 584; //構造体メンバを指すポインタ std::cout << "*p = " << *p << std::endl; std::cout << "z.d = " << z.d << std::endl; std::cout << "p = " << p << std::endl; std::cout << "&z.d = " << & z.d << std::endl; std::cout << "z.*o = " << z.*o << std::endl; std::cout << "z.*o = " << &o << std::endl; } |
ラムダ式クロージャ
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#include <iostream> //通常関数またはラムダで(↓は通常関数とラムダ)2重にしてキャプチャでコピーしてmutable(デフォconst解除) auto f(int a) { int x = a; return [x](int n)mutable { std::cout << x << ":" << n << std::endl; ++x; }; } int main() { { auto s = f(0); s(1); s(1); s(1); } auto s = f(0); s(1); s(1); s(1); } |
リークチェック、const、ポインタ
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
#include <iostream> #include <stdlib.h> char* f(const char** p) { std::cout << "sub " << *p << std::endl; char* const u = (char*)malloc(sizeof p); // *後にconstをつけることによってfreeを確実に行える、ポインタ位置が変わらないため memcpy(u, *p, sizeof u); if (u) //十分なメモリ容量を使用できない場合に malloc を呼び出すと null が返される可能性があるためnullチェックをする { *u = 'r'; return u; } } char* f(char *p) { *p = 'y'; return p; } void ggg(int& a) { a += 5555; } void aaa(int* a) { *a -= 6000; } int main() { _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF); //リークチェック治具 const char* a = "abc"; // *前にconstはポインタ位置は変更可能、中身が変更不可 std::cout << "a= " << a << std::endl; a += 1; ++a; std::cout << "+++a= " << a << std::endl; a = "ghj"; std::cout << "aにghj= " << a << std::endl; char b = *a; std::cout << "b=*a= " << b << std::endl; // *a = 'a' ポインターを通しての中身の変更不可 // ++*a 先頭文字をインクリメントして変更不可 const char* const c = "top"; // *の後に書いたconstは先頭ポインタで固定、 ++c等も不可 const int i = 123; // ++i i += 2 i = 3 NG char p[] = "alpha"; //配列は変数(スタック領域)なので変更可能 const char* j = "alpha"; //ポインタを使うと文字列リテラル(スタティック領域)になる為変更不可、constは外すとエラー //関数先でコピーを作って返せば変更可能 std::cout << "@@" << *j << std::endl; std::cout << "@@" << j << std::endl; std::cout << "@@" << &j << std::endl; char* m = f(p); if (j); //ポインタを渡すときは必ずnullチェックを行う!!! char* t = f(&j); std::cout << m << std::endl; std::cout << t << std::endl; free(t); int g = 1234; ggg(g); // 関数側で参照で受け取れば中身変更可能 C++ver std::cout << g << std::endl; aaa(&g); // 呼び出しで参照にして引数でポインタにする Clang std::cout << g << std::endl; } |
右辺値参照
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include <iostream> #include <vector> void f(const char*&& a) { std::cout << a << std::endl; } template<typename T> void f1(T&& a) { for (auto d : a) std::cout << d << std::endl; } int main() //一時オブジェクト { f("aaa"); f1(std::vector<int>{1, 2, 3, 4}); } |
可変式引数
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <iostream> #include <stdio.h> #include <vector> #include <wchar.h> #include <string> #include <vector> template<class... T> void f(T&&... a) { int y[] = { a... }; for (auto s : y) { std::cout << s << std::endl; } } int main() { f(1, 2, 3, 4, 5, 6, 7, 8, 9, 0); } |
関数で演算子
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include <iostream> void f(bool q) { std::cout << q << std::endl; } int g() { return 10; } int h() { std::cout << "lol" << std::endl; return 0; } int main() { int a = 10; int b = 20; f(a > b); f(a < b); g() && h(); //&&は真なら次を評価、左から必ず評価される &一つは必ずではない } |
偶数奇数処理
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#include <iostream> #include <stdio.h> #include <vector> #include <wchar.h> #include <string> #include <tuple> int sum(const std::tuple<const int*, const int*, bool(*)(int) >& r) { int retval = 0; for (const auto* first = std::get<0>(r); first < std::get<1>(r);) { const auto d = *first++; if ((*std::get<2>(r))(d)) retval += d; } return retval; } std::ostream& operator<<(std::ostream& ostm, const std::tuple<const int*, const int*, bool(*)(int) >& r) { int retval = 0; for (const auto* first = std::get<0>(r); first < std::get<1>(r);) { const auto d = *first++; if ((*std::get<2>(r))(d)) std::cout << ' ' << d; } return ostm; } int main() { int a[7]{ 56,15,48,32,45,44,77 }; const auto even = std::make_tuple(a, std::end(a), [](int d) {return (d & 1) == 0; }); const auto odd = std::make_tuple(a, std::end(a), [](int d) {return (d & 1) == 1; }); std::cout << "偶数 " << even << " 合計= " << sum(even) << '\n'; std::cout << "偶数 " << odd << " 合計= " << sum(even) << '\n'; } |
構造体オペレーター
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#include <vector> #include <iostream> #include <string> struct sample { std::string s; explicit operator bool() const { return !s.empty(); //sが空じゃなければtrue } explicit sample(int n) :s(std::to_string(n)) { } void operator() (int& s) const { std::cout << s << std::endl; } }; void f(const int& a) { std::cout << a << std::endl; } int main() { sample x(123); if (x) //if(x)でコンストラクタのオペレータが呼ばれる(ifでboolが必要なので { } int v = 1; x(v); std::cout << x.s << std::endl; const int z[] {11,22}; const int* o = z; f(*o); } |
電卓入力
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include <iostream> int main() { int a = 222; int 入力値 = 1; if (a > 0) { a = a * 10; a += 入力値; } else { a += 入力値; } std::cout << a << std::endl; } |
配列を指すポインタ
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include <iostream> #include <stdio.h> #include <vector> #include <wchar.h> #include <string> #include <vector> int main() { puts("ABC\0CDE\0EFG\0JKL" + 2); puts("ABC\0CDE\0EFG\0JKL" + 3); puts("ABC\0CDE\0EFG\0JKL" + 4); for (int i = 0; i < 4; ++i) puts(((const char(*)[5])"ABCD\0EFGH\0IJKL\0MNOP")[i]); //配列を指すポインタ // ↑要素数5個の配列を指すポインタ にキャストしてる // (*)←()が無いとポインタ配列になる } |
配列要素数+1
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include <iostream> #include <stdio.h> #include <vector> #include <wchar.h> #include <string> #include <vector> int main() // (&aaa)[1] で最終配列の次のアドレスを指せる { int aaa[3]{ 1,2,3 }; std::cout << &aaa[0] << std::endl; std::cout << &aaa[1] << std::endl; std::cout << &aaa[2] << std::endl; std::cout << &aaa[3] << std::endl; std::cout << &aaa[sizeof aaa / sizeof * aaa] << std::endl; std::cout << (&aaa)[1] << std::endl; } |
文字
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include <iostream> #include <Windows.h> int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { //LPWSTR wchar_t aaa[]{ L"aaa" }; //LPCWSTR const wchar_t* bbb[2]{ L"lol", L"www" }; LPWSTR a = aaa; // NG LPWSTR a = bbb[0]; } |

コメント