C++ 문자열 대문자로 변환

(C++ strtoupper()에서 넘어옴)

1 개요[ | ]

C++ 문자열 대문자로 변환
C++ strtoupper() 구현
C++ uppercase() 구현
C++
CPU
0.4s
MEM
47M
0.7s
Copy
#include <iostream>
using namespace std;
string strtoupper(string str) {
    for(auto &c: str) c = toupper(c);
    return str;
}
int main() {
    cout << strtoupper("Hello World!") << endl; // HELLO WORLD!
}
HELLO WORLD!
C++
Copy
#include <iostream>
#include <algorithm>
using namespace std;
string strtoupper(const string str) {
    string ret = str;
    transform(ret.begin(), ret.end(),ret.begin(), ::toupper);
    return ret;
}
int main() {
    cout << strtoupper("Hello World!") << endl; // HELLO WORLD!
}
Loading

2 같이 보기[ | ]