ベスパリブ

プログラミングを主とした日記・備忘録です。ベスパ持ってないです。

2018-11-28から1日間の記事一覧

【C++】charからstringへの変換

C++

C++全然わからん。 #include <iostream> #include <string> #include <map> using namespace std; int main(int argc, char const *argv[]){ string s = "ABC"; map<string, int> mp; mp["A"] = 0; //mp[s[0]]++; // エラー mp[{s[0]}]++; cout << mp["A"] << endl; return 0; } char型のものは{}</string,></map></string></iostream>…

C++で文字列のスライス

C++

C++全然わからない。 最近C++を使っているのですが、Pythonでいう文字列のスライスが使いたい。 s = "abcdef" print(s[0:3]) # ==> "abc" こんなの。 調べてもないっぽいのでそれっぽいものを実装。 #include <iostream> #include <string> using namespace std; string str_sl</string></iostream>…