Visual C 以前的文本在终端中删除并替换为新文本
visual C++ Previous text erased and replaced by new text in terminal
这是我的代码。
#include <iostream>
#include <string>
#include <windows.h>
#include <iomanip>
using namespace std;
int main(){
char choice;
do{
double x;
double y;
char z;
double sum;
cout << "Pick a operation + - * /" << endl;
cin >> z;
cout << "Enter a number" << endl;
cin >> x;
cout << "Enter another number" << endl;
cin >> y;
if (z == '+'){
sum = x + y;
cout << "Answer: " << sum << endl;
}
else if (z == '-'){
sum = x - y;
cout << "Answer: " << sum << endl;
}
else if (z == '-'){
sum = x - y;
cout << "Answer: " << sum << endl;
}
else if (z == '*'){
sum = x * y;
cout << "Answer: " << sum << endl;
}
else if (z == '/'){
sum = x / y;
cout << "Answer: " << sum << endl;
}
cout << "Would you like to enter another equation? (y/n)" << endl;
cin >> choice;
} while (choice != 'n');
if (choice == 'n'){
return 0;
}
system("PAUSE");
return 0;
}
我要做的就是做到这一点,以便替换当前行,而不是每个新的cout
转到另一行。基本上,除了cin
外,所有将发生在一行中,该行将出现在cout
下方的行中。我知道我可以使用r
,但是cin
将尝试覆盖cout
。我希望删除cin
输入,然后cout
将替换以前的cout
。
我是一个总的初学者,所以我真的不知道该怎么办。
现代控制台模拟器足够快,您可以清除屏幕并简单地重新打印要保留的文本,而不会引人注目。如前所述,您也可以使用诅咒库。
您知道这一点,但是:当您打印运输返回字符 r
时,许多终端都会这样做。从历史上看,当电视具有物理打字机的打印轮和车厢时,这将使马车返回左位并允许覆盖。在某些机器(包括经典的Macintoshes(上,这将有其他作用,但是它将在当今大多数游戏机上使用,包括Windows cmd.exe
,OS X和Linux。
虽然有这样做的方法,但它们都不是标准的。此链接显示ANSI逃生序列,但是每个终端都不同,请记住文档是您的朋友。
相关文章:
- 尝试将文本文件中的整数替换为用户输入的整数 [C++]
- 如何使用regex_replace将子字符串替换为字符串中的另一个子字符串,同时保持整个文本完整?
- 如何在给定文本中用字符数组替换符号
- 创建程序以从给定的.txt文件中查找文本,替换并计算单词
- 将文本流中一个字符串的所有匹配项替换为另一个字符串
- 外壳追加重定向替换现有文本
- Visual C 以前的文本在终端中删除并替换为新文本
- 尝试在自定义 QT 创建器文本编辑器中创建查找和替换循环.我似乎无法设置光标位置
- 我将如何替换命令提示符上的文本?C
- 如何替换QT QML中的变体数组文本
- 从文本文件中读取并替换文本,C
- 我想自动替换特定文本
- IE 探索 11 < c++ ATL COM 浏览器帮助程序对象(加载项)来替换 DOM 中的文本
- 使用C 替换文本文件中的单词
- Visual Studio,在(解决方案资源管理器的)某个筛选器内的所有文件中查找/替换文本
- 通过文本文件逐字通知并替换某些单词
- 使用 C++ 替换 txt 文件中的文本数字字符串
- 如何用不同的文本替换文本文件上的某一行
- C++如何创建"绑定"字符串文本替换方法?
- 用C++宏将文本替换为空