C++ split



C++ 에서 간단하게 문자열 파싱하기

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

int main()
{
    std::wstring text;
    std::wstring data = L"000;123;333";
    
    std::wistringstream token_stream(data.c_str());
    
	while (std::getline(token_stream, text, L';'))
	{
		if (!text.empty())
		{
		    std::wcout << text << std::endl;
		}
	}
}

문자열로 파싱하기


#include <iostream>
#include <string>

int main()
{
    std::string s = "scott>=tiger>=mushroom";
    std::string delimiter = ">=";

    size_t last = 0;
    size_t next = 0; 
    while ((next = s.find(delimiter, last)) != std::string::npos) 
    { 
        std::cout << s.substr(last, next-last) << std::endl; 
        last = next + delimiter.length(); 
    } 
    std::cout << s.substr(last) << std::endl;
}






© 2018. by brian jung

Powered by storm