如何打印字符串而不是数字
How to print string instead of numbers
我有一个名为Truth Table的程序。如何打印"T"和"F"而不是 1 和 0? 以下是一些代码
string Choice, UserInput, NotChoice;
bool FirstChoice[2] = { true, false };
bool ValidInput = false;
bool InvertChoice = false;
cout<<"Enter a Hypothesis: ";
cin>>Choice;
do
{
ValidInput = false;
cout<<"Do you want to NOT "<<Choice<<"?(Y/N): ";
cin>>UserInput;
toUpper(UserInput);
if (UserInput == "Y")
{
InvertChoice = true; ValidInput = true;
}
else if (UserInput == "N")
{
InvertChoice = false; ValidInput = true;
}
else
{
cout<<"ERROR: Please enter valid values [Y, N]" << endl;
}
}
while (!ValidInput);
NotChoice = "~" + Choice;
cout<< Choice << (InvertChoice? " | ":"") <<(InvertChoice? NotChoice : "" )<<endl;
for ( int x = 0; x < 2; x++)
{
bool FirstValue = InvertChoice ? !FirstChoice[x] : FirstChoice[x];
for ( int z = 0; z < 1; z++ )
{
if ( InvertChoice == true )
{
cout<< setw(1) << FirstChoice[x] << " | " << FirstValue << endl;
}
else
{
cout<< setw(1) << FirstChoice[x] << endl;
}
}
}
我想像这样打印它
Q | ~Q
T |F
F |T
这是实际输出
Q | ~Q
1 | 0
0 | 1
您可以使用std::boolalpha
打印"true"和"false"。
std::cout << std::boolalpha << true;
或者根据布尔值选择一个字符串
bool x = true;
std::cout << (x ? "T" : "F");
相关文章:
- 生成随机长度的数字字符串
- 如何在c ++中将大数字字符串转换为整数?
- 将非数字字符串存储为二进制整数
- Flex 词法分析器规则,对包含连字符和斜杠的字母数字字符串具有积极的前瞻断言
- 如何在C++中将数字字符串拆分为数组
- 总结数字字符串输入的最佳方法
- 如何将输入的数字字符串转换为 int 数组
- 如何获得两个数字字符串的总和-C
- 使用 C++ 替换 txt 文件中的文本数字字符串
- 如何有效地将数字字符串值分配给整数
- String Stream in C++ 解析单词和数字字符串
- c++将大型数字字符串映射到数字字符串范围
- 获取用数字字符串表示的树中的所有直接父级/子级
- 如何从 char 数组中提取数字字符串成员
- 比较两个字母数字字符串
- 有没有一种方法可以设置浮点变量=某个数字*字符串中的变量
- 使用矢量对字母数字字符串进行排序
- 正在分析未知类型的数字字符串
- 如何在c++中从一个科学数字字符串中修剪后面的零
- 无法将字符串数组中的数字字符串转换为浮点值