Home > database >  VS Code exits without displaying any output when a character array is taken as input
VS Code exits without displaying any output when a character array is taken as input

Time:11-11

I have tried updating my g installation but there has been no solution. Here is the code.

#include <iostream>
using namespace std;
#include<string>
#include <cstring>
int main()
{
    char str[100];

    cout << "Enter a string: ";
    cin>>str;
    cout << "You entered: " << str << endl;

    cout << "\nEnter another string: ";
    cin>>str;
    cout << "You entered: "<<str<<endl;

    return 0;
}

The output that this code shows is: Check the terminal

Please give me a solution or at least a reason for this. I am new to Stack Overflow so please free to correct me if I made any mistake in the post. [This problem only happens in vs code but works in online gdb compiler.]

Edit:After I tried executing this in the cmd line this what it shows

cmd line execution

CodePudding user response:

The output you're seeing is from some kind of makefile. You didn't say how you're trying to build the file so it's hard to say what caused the issue.

However, you can simply compile your file directly by typing g hgg.cpp -o hgg in the command shell

CodePudding user response:

After writing the code, switch to Command Prompt (Cntrl x) move to the directory, in which the C program is present.

Then run the following:

g   -Wall filename.cpp -o filename

If nothing is printed on the console, then your code is syntactically correct. Then do the following:

filename.exe

It should work now.

  • Related