티스토리 뷰

Ongoing/String

for [C/C++] char[] string

More Code 2018. 6. 21. 21:26


#include <iostream>

using namespace std;

int main(int argc, char **argv) {
char words[] = "Hello";

for (auto t : words) {
cout << t << endl;
}

return EXIT_SUCCESS;
}

/* Output
H
e
l
l
o
*/



#include <iostream>

using namespace std;

int main(int argc, char **argv) {
string words = "Hello";

for (auto t : words)
{
cout << t << endl;
}

return EXIT_SUCCESS;
}

/* Output
H
e
l
l
o
*/



#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char **argv) {
    vector<string> animals = { "cat", "dog", "fox" };

    for (string article : animals) {
        cout << article.c_str() << endl;
    }

    return EXIT_SUCCESS;
}

/* Output
cat
dog
fox
*/


'Ongoing > String' 카테고리의 다른 글

[C# C++ Python] verbatim string, raw string literal  (0) 2019.04.19
[C#] Composite Format String & Interpolated String  (0) 2018.07.09
for [Java] String  (0) 2018.06.20
for foreach [C#] string  (0) 2018.06.20
for [Python] string  (0) 2018.06.20
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함