问题描述
c/c++ 创建元素个数为500的字符串数组 读了500个长度不超过40的字符串,再输出,大家都是怎么写的?(我知道这个问题很low)
问题解答
回答1:#include <string>#include <iostream>using namespace std;int main(){ string xs[500]; for (auto& x : xs) {cin >> x;if (x.size() > 40) /*do something to crash*/; } for (const auto& x : xs) {cout << x << endl; }}