如何将多个整数赋值给另一个整数
How do I assign mutiple integers to another integer?
这是真正的代码如果我输入数字1009,我希望输出的数字是7687,现在这不是问题。在最后一个cout语句中,当我输入encryptnum时,我希望它输出7687,所以我不需要输入cout <<第一& lt; & lt;第二& lt; & lt;第三& lt; & lt;第四,
#include <iostream>
using namespace std;
int main()
{
int num;
int first;
int second;
int third;
int fourth;
int encryptnum;
cout << " Enter a four digit number to encrypt ";
cin >> num;
first = num % 100 / 10;
second = num % 10;
third = num % 10000 / 1000;
fourth = num % 1000 / 100;
first = (first + 7) % 10;
second = (second + 7) % 10;
third = (third + 7) % 10;
fourth = (fourth + 7) % 10;
encryptnum = //I want to make encryptnum print out first, second, third, and fourth
cout << " Encrypted Number " << encryptnum;
return 0;
}
根据你的评论(你应该把评论和问题结合起来,使你的目标更明确),这应该对你有帮助:
#include <iostream>
#include <sstream>
int main()
{
int first, second, third, fourth;
int all;
std::cout << " Enter four numbers ";
std::cin >> first >> second >> third >> fourth;
std::stringstream s;
s << first << second << third << fourth; //insert the four numbers right after each other
s >> all; //read them as one number
return 0;
}
相关文章:
- 为"adjacent"变量赋值时出现问题
- C++中的赋值发生,尽管右侧出现异常
- 用C++中的sscanf赋值
- 为std::string的某个索引赋值
- 重载Singly Linked List中的赋值运算符
- 为什么我必须在C++中添加一个赋值符号来声明一个数组
- gtest_使用setargpointee在函数中赋值
- 非常量变量只读位置的赋值
- 字符串 c++ 的不明确整数赋值
- 有可能将多个整数赋值为一吗
- gcc 的 -Wconversion 是否与使用比 int 短的整数类型的复合赋值(+= 等)不兼容?
- 在sparcsolaris上使用gcc为长整型整数赋值
- 可以将lower_bound(来自c++ STL)的结果赋值给整数类型变量吗?
- 如何将多个整数赋值给另一个整数
- 为什么我必须将地址强制转换为整数以使其可赋值?
- 整数变量的值被神秘地重新赋值
- 如果我将带小数点的数字赋值给整数而不是浮点数会发生什么?
- 无法为整数类型的变量赋值
- 将函数的声明设置为0是什么意思?如何将整数赋值给函数?
- 将较小的整数类型赋值给较大的整数类型是否不安全?