|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 bin554385863 于 2019-8-17 12:07 编辑
- #include <iostream>
- #include <vector>
- #include <cctype>
- /*输入10个数字使用迭代器翻倍输出*/
- int main(int argc, char const *argv[])
- {
- using namespace std;
- vector<int> intvec;
- int c = 0;
- int num;
- while (c != 10)
- {
- c++;
- cin >> num;
- /*
- if()
- {这里如何判断输入的是数字而不是其他字符,数字大小有可能超出Char类型的最大值}
- */
- intvec.push_back((int)num);
- }
- for (vector<int>::iterator it = intvec.begin(); it != intvec.end(); it++)
- {
- *it = *it * 2;
- cout << *it << " ";
- }
- return 0;
- }
复制代码
---------------------------------------------------------------------------------------------
Microsoft Windows [版本 10.0.16299.1087]
(c) 2017 Microsoft Corporation。保留所有权利。
E:\Users\86184\Documents\Code>c:\Users\86184\.vscode\extensions\ms-vscode.cpptools-0.24.1\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-2li3xujz.b4x --stdout=Microsoft-MIEngine-Out-irxnjzh0.lkv --stderr=Microsoft-MIEngine-Error-mit5ew1z.1bb --pid=Microsoft-MIEngine-Pid-u3m1o4fz.0wb "--dbgExe=E:\My Program\MinGW\bin\gdb.exe" --interpreter=mi
1234 2345 32 1 2 3 4 5 6 7
2468 4690 64 2 4 6 8 10 12 14
E:\Users\86184\Documents\Code>
---------------------------------------------------------------------------------------------------------
- c++;
- cin >> num;
- /*
- if()
- {这里如何判断输入的是数字而不是其他字符,数字大小有可能超出Char类型的最大值}
- */
- intvec.push_back((int)num);
- }
- for (vector<int>::iterator it = intvec.begin(); it != intvec.end(); it++)
- {
复制代码
求解,isdigit()没卵用 |
|