c++ - C ++如何引用用户输入?
问题描述
如何引用用户输入的整数以及结果。例如,我正在尝试打印此代码,二进制格式的数字“12”是“1100”
我的代码;
#include <iostream>
using namespace std;
void decimalToBinary();
int main()
{
decimalToBinary();
return 0;
}
void decimalToBinary()
{
int array[32];
int number, index;
cout << "Enter a number to convert to binary: ";
cin>>number;
cout << endl;
cout << "The number " << number << " in binary format is ";
for(index=0; number>0; index++)
{
array[index]=number%2;
number= number/2;
}
for(index=index-1 ;index>=0 ;index--)
{
cout << array[index];
}
}
解决方案
您需要放置一个 \(转义序列,与 \n 或 \t 使用的方法相同)以表明引号将被忽略:
cout << "The number \" " << number << " \" in binary format is ";
推荐阅读
- javascript - 从子元素设置父样式
- javascript - 在 Slate.js 编辑器中启用自动链接
- javascript - 为什么 useCallback 是同一个实例
- rest - 从 Snapchat 自定义镜头调用 rest API
- python - 将尖括号嵌入的 UTF-8 十六进制值转换为重音字符
- android - Flutter - setState 到另一个类
- javascript - jquery在.each循环中强制延迟并触发click()
- java - 如何使用这个库,它只有 .java 文件
- angular - 如何将离子日期时间选择器更改为本地时间?
- python - 添加自定义文件名django模型(models.FileField)