ProgrammingLang/c++

[C++개발자되기]23. 문자열 다루기

jinkwon.kim 2021. 10. 7. 13:04
728x90
반응형

문자열 대문자로 변경

#include <algorithm>
#include <string>

std::string str = "Hello World";
std::transform(str.begin(), str.end(),str.begin(), ::toupper);

 

문자열 parsing

#include <iostream>

std::string s = "ITEM=this is value";
std::string value = s.substr(s.find("=") + 1);

 

argv  to vector string

#include <iostream>
#include <vector>

int main(int argc, const char** argv) 
{
	std::vector<std::string> arguments(argv + 1, argv + argc);
}

 

문자열 비교 

#include <iostream>

int main(int argc, const char** argv)
{
    std::string cmp = "test";

    if (0 == cmp.compare("test")) {
            std::cout << "Match" << std::endl;
    }

    return 0;
}

 

 

728x90
반응형