Akshat
Akshat

Reputation: 1

My C++ code is not taking any input, only cin is causing the trouble not cout. Even the online compilers are showing timeout error

The cpp code that I wrote while solving an online solution, was running indefinitely, even though it was not supposed to. So I pinpointed the line that was causing the problem- it was the cin line.

I don't know what is happening here, even the online compiler is showing timeout error in the code. This all started when I was practicing questions on codeforces and when I run it, it was running indefinitely.

The original code screenshot->

the code that I typed on my machine, which was running indefinitely

#include<iostream>
using namespace std;

int main() {
    int t;
    cin >> t;
    cout << "hello world, the value of t is = " << t << endl;

    return 0;
}

The code in question->

the hello world code, in an online compiler showing timeout error

#include<iostream>
using namespace std;

int main() {
    int t;
    cin >> t;
    cout << "hello world, the value of t is = " << t << endl;

    return 0;
}

What can I try next?

Upvotes: 0

Views: 31

Answers (1)

Mani Kiran
Mani Kiran

Reputation: 1

This is neither a compilation error nor a timeout. The program is simply waiting for you to provide input (enter the value of 't'). After running the code, input an integer, and you will see the output.

It looks like your understanding of C++ fundamentals needs improvement. I recommend reading more about C++ or watching some tutorials to strengthen your basics.

Upvotes: 0

Related Questions