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
*/