c_cpp 根据空间拆分字符串并将每个标记转换为大写。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 根据空间拆分字符串并将每个标记转换为大写。相关的知识,希望对你有一定的参考价值。

#include <sstream>
#include <iostream>
#include <string>
#include <algorithm>

std::string toupper(std::string& s) {
    for(std::string::iterator c=s.begin(); c!=s.end(); c++) {
        *c = std::toupper(*c);
    }
    return s;
}

int main(int argc, char* argv[]) {
    std::string s = "Innovation links to the future";
    std::string token;
    std::istringstream is(s);

    while(is >> token) {
        std::cout << "token: " << toupper(token) << std::endl;
    }

    return 0;
}

以上是关于c_cpp 根据空间拆分字符串并将每个标记转换为大写。的主要内容,如果未能解决你的问题,请参考以下文章