c/c++ 创建元素个数为500的字符串数组 读入500个长度不超过40的字符串,再输出,大家都是怎么写的?

c/c++ 创建元素个数为500的字符串数组 读了500个长度不超过40的字符串,再输出,大家都是怎么写的?(我知道这个问题很low)

阅读 4k
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;
    }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题