#include <iostream> #include <cctype> #include <string> const int Max = 5; int main(int argc, char const *argv[]) { using namespace std; int golf[Max]; int i; for (i = 0; i < Max; i++) { std::cout << "round #" << i+1 << ' '; while (!(cin >> golf[i])) { cin.clear(); cin.get(); // while (cin.get() != ' ') { // continue; // } std::cout << "please enter a number:" << ' '; } } double total = 0.0; for (i = 0;i < Max; i++) { total += golf[i]; } std::cout << total << ' '; return 0; }
int vector_begin(){ vector<string> words; string str; cout << "please input you content==>:" << ' '; while (cin >> str){ words.push_back(str); if (cin.get() == ' '){ break; } } vector<string>::iterator iter; for (iter =words.begin(); iter != words.end(); iter++){ cout << *iter << ' '; } return 0; } int main () { // assign(); vector_begin(); return 0; }