我想写一个 for 循环来传递 0 到 9 的字符串:
for (string j = "0"; j < "10"; j++) {
}
但它不知道运算符++(它得到一个整数 (1) 而不是字符串“1”)。
我想写:j+="1"
,然后 j
将是 "01"
然后 "011"
...
附注我不想使用 #include <string>
的功能或者是其他东西。 (stoi 等)
感谢任何帮助!
最佳答案
用整数循环,然后手动将其转换为字符串?
喜欢
for (int i = 0; i < 10; i++)
{
string j(1, '0' + i); // Only works for single digit numbers
}
关于c++ - for 循环 : a string passes from "0" to "9",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15784521/