0

嗨,我正在编写这个程序,但我什至无法开始查看其他代码是否有问题。

我有这个:

    int main()
{
    int answer;
    int test;
    cout << "Please Enter the number to be tested: ";
    cin >> test; //Gets number to be tested
        cout << "here";
    answer = factor(test);
    cout << "The answer is:" << answer;
    return 0;
}

接着。它会打印出第一个 cout,然后它会到达 cin,获取数字但不会做任何事情。甚至不会打印第二个 cout。有任何想法吗?

我很新,并没有真正做太多,所以欢迎任何额外的把我当作白痴的解释。:D 谢谢。

4

5 回答 5

3

也许因子函数有问题?无限循环?然后 cout << "这里" << endl; (刷新输出)至少应该打印“here”。

于 2010-11-19T10:25:29.197 回答
1

我猜你的台词<< endl;中缺少。cout这会导致输出缓冲区不会被刷新,并且屏幕上不会出现任何内容。尽管这可能取决于您运行它的平台。它可能适用于某些永久刷新输出缓冲区的系统。

int main()
{
int answer;
int test;
cout << "Please Enter the number to be tested: ";
cin >> test; //Gets number to be tested
    cout << "here" << endl;
answer = factor(test);
cout << "The answer is:" << answer << endl;
return 0;
}
于 2010-11-19T10:24:47.567 回答
0

看起来程序正在等待终端的输入。一旦您提供输入然后按“Enter”,它将自动考虑输入并且下一个 cout 语句工作正常......检查下面的代码段......(除了因子的虚拟实现之外没有任何修改,这不是主题在这里讨论)

enter code here

包括

使用命名空间标准;

int 因子(int t) { 返回 t; }

int main()

{ 诠释答案; 智力测验;cout << "请输入要测试的数字:"; cin >> 测试; //获取要测试的编号 cout << "here"; 答案=因子(测试);cout << "答案是:" << answer; 返回0;}

O/p is : $ ./a.out 请在此处输入要测试的号码:1234 答案是:1234user@ubuntu:~$ ./a.out 请在此处输入要测试的号码:1234 答案是:1234$

于 2010-11-19T10:37:55.107 回答
0

当我在输入后立即在键盘上按 Enter 时,我得到了相同的结果。如果我点击返回,那么程序运行良好。我以为进入和返回是一回事?

于 2010-12-11T10:25:38.663 回答
-1
This is how it work "here " your screen doesnot be static by putting system("pause") you can do it ,on the other hand i have just made the function defination dummi still happen anything check there]


#include<iostream>
using namespace std;
int factor(int x)
{
    return x;
}
int main()
{
    int answer;
    int test;
    cout << "Please Enter the number to be tested: ";
    cin >> test; //Gets number to be tested
    cout << "here";
    answer = factor(test);
    cout << "The answer is:" << answer;

    **system("pause");**


}
于 2016-03-01T12:33:27.357 回答