如何将长字符串拆分为短字符串?
  • 板块题目总版
  • 楼主juice88
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/3/24 19:37
  • 上次更新2024/3/24 21:09:05
查看原帖
如何将长字符串拆分为短字符串?
1280440
juice88楼主2024/3/24 19:37

此贴用于个人记录。

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

int main() {
    string s, s1;
    int x = 0;
    cin >> s;
    s += ',';
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == ',') {
            s1 = s.substr(x, i - x);
            x = i + 1;
            cout << s1 << endl;
        }
    }
    return 0;
}
2024/3/24 19:37
加载中...