在textmate中使用cin和cout
using cin and cout in textmate
我通常是一个Java程序员,并且几乎专门使用textmate,但最近我开始使用c++。但是当我使用最基本的程序并合并cin关键字,并运行程序时,我没有机会在运行时输入任何东西,有时它自己插入随机值!例如,如果我在textmate:
中运行这个#include <iostream>
int stonetolb(int);
int main() {
using namespace std;
int stone;
cout << "enter the weight in stone";
cin >> stone;
int pounds = stonetolb(stone);
cout << stone << "stone = ";
cout << pounds <<" pounds.";
return 0;
}
int stonetolb(int sts) {
return 14 * sts;
}
我将输出:
输入stone32767stone = 458738磅的重量。
为什么会发生这种情况,我该如何阻止它?
很可能是输入语句cin >> stone
失败,stone的值未定义。需要使用if (cin >> stone) { ... } else { // input failure }
检查输入是否失败。至于为什么这样一个简单的程序会表现出失败的行为,我不知道—您必须检查textmate文档。
相关文章:
- 为什么 printf 在 C++ 中的执行速度比 cout 快?另外scanf比cin慢,为什么?
- 使用 CIN COUT 显示垃圾值的文件对象?
- 当我们声明 cin 为 int 并从 cin 中获取输入并在 cout 中打印 cin 时会发生什么?
- 为什么我的 cout 一次执行,尽管 cin 应该在两者之间读取?
- 两个 cin / cout 语句合并为一个
- 防止 cin、cout、cerr 被实例化
- 无法让我了解 cin.get 和 cout 在这里的工作方式
- 使用 std::endl 与 "n" 当 cin 和 cout 被解绑时
- CIN 和 COUT 如何在以下程序中工作
- 使用自定义宏来简化 cin 和 cout 语句等内容被认为是更好还是更差
- 简单的cin cout代码由"build and run"运行,但从bin/debug/x开始工作.exe
- 通过 cin/cout 的协议单元测试 - 如何阻止流以等待内容?
- 为什么 CIN / COUT 比 scanf/printf 慢
- 从printf-scanf转换为cin-cout时出现问题
- cin/cout 使用什么技术/模式允许例如 cout << x << y
- 为什么我不能将 cin/cout 放在一个函数中并从 main() 调用该函数
- 交替使用cin/cout很慢
- 关于 cin/cout 过载的简单问题 4.
- cin / cout being skipped
- c++, cin, cout, threads和sync_with_stdio的输出损坏