0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

C++ 標準入出力 メモ

Last updated at Posted at 2022-02-21

競技プログラミングなどの問題解くときに必要になる基本的なコードのメモ。

標準入力読み取り 行毎

    using namespace std;

    string l;
    while (getline(cin,l)) {
        // 2行目以降の処理
    }

スペース区切りstring 数値変換

#include <iostream>
#include <string>
#include <sstream> // istringstream

using namespace std;
int main(void){

string l("123 678");
int a1(0),a2(0);
istringstream iss = istringstream(l);
iss >> a1 >> a2;
cout << a1 << endl;
cout << a2 << endl;
}

# 文字列→数値 (stoi)

#include <iostream>
#include <string>
using namespace std;

auto i = std::stoi("123");
cout << i << endl;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?