Skip to content

Instantly share code, notes, and snippets.

@sifue
Created September 15, 2015 06:13
Show Gist options
  • Select an option

  • Save sifue/5849d68919bd7746bb73 to your computer and use it in GitHub Desktop.

Select an option

Save sifue/5849d68919bd7746bb73 to your computer and use it in GitHub Desktop.
C++で標準出力から得た数値を足し算するだけのもの
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <typeinfo>
using namespace std;
int main()
{
string str;
vector<int> data(5);
int sum = 0;
while (getline(cin, str))
{
cout << "[" << str << "]" << endl;
data.push_back(atoi(str.c_str()));
}
cout << "Input finished." << endl;
for (int i = 0; i < data.size(); ++i) {
sum += data[i];
}
cout << "Sum=" << sum << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment