[C++ 자료구조 <string> ]substr 사용법 메모

[C++ 자료구조 <string> ]substr 사용법 메모

http://www.cplusplus.com/reference/string/string/substr/

 

string::substr - C++ Reference

12345678910111213141516171819 // string::substr #include #include int main () { std::string str="We think in generalities, but we live in details."; // (quoting Alfred N. Whitehead) std::string str2 = str.substr (3,5); // "think" std::size_t pos = str.find

www.cplusplus.com

사용

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
using namespace std;
 
int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    string str = "abcdefghijk";
    for (int i = 0; i < str.length(); i++)
    {
        cout << str.substr(i) << '\n';
    }
    return 0;
}
 
 

결과