|  | 
 
 发表于 2019-8-16 23:16:26
|
显示全部楼层 
| 
 可以的,你这程序逻辑也有问题,把数字都push进vec后 遇到不是数字就return了?下面迭代输出过程没了?
 
 下面这段代码VS2019编译运行没问题
 
 
 复制代码#include <iostream>
#include <vector>
#include <cctype>
/*使用迭代器将输入的数字翻倍输出*/
int main(int argc, char const* argv[])
{
        using namespace std;
        vector<int> intvec;
        char num;
        while (true)
        {
                cin >> num;
                if (isdigit(num) == false)
                {
                        cout << "请输入数字";
                        break;
                }
                else
                {
                        intvec.push_back(num);
                }
        }
        for (vector<int>::iterator it = intvec.begin(); it != intvec.end(); it++)
        {
                *it = *it - '0';
                *it = *it * 2;
                cout << *it << " ";
        }
        return 0;
}
 输入输出
 
 
 复制代码1
2
3
4
5
6
#
请输入数字2 4 6 8 10 12 请按任意键继续. . .
 | 
 |