C++string能拆分成一个一个字符吗?
C++string类能拆分成一个一个字符吗? 什么意思?#include <iostream>
#include <string>
using std::cout, std::endl;
using std::string;
int main() {
string str = "hello world!";
for(size_t i = 0; i < str.size(); ++i) {
cout << str << endl;
}
return 0;
}
#include <iostream>
int main() {
std::string myString = "Hello World!";
for (const char& c : myString) {
std::cout << c << std::endl;
}
return 0;
}
页:
[1]