stdstring input = 123456 要遍历出input 使用c++98实现给出实现代码
以下是使用C++98实现遍历字符串的代码:
#include <iostream>
#include <string>
int main() {
std::string input = "123456";
for (std::string::iterator it = input.begin(); it != input.end(); ++it) {
std::cout << *it << " ";
}
return 0;
}
这段代码使用了std::string::iterator来遍历字符串input的每个字符。通过input.begin()和input.end()可以获取到字符串的起始和结束迭代器,然后使用循环遍历每个字符,并使用*it来访问字符的值。在循环中,我们使用std::cout输出每个字符,并在字符后面加上一个空格。
原文地址: http://www.cveoy.top/t/topic/isu0 著作权归作者所有。请勿转载和采集!