C++ skips all cin statements

I'm a beginner in C++ and I wrote this simple code:

1
2
3
4
5
6
7
8
9
10
11
12
13
  #include <iostream>                                                         
  using namespace std;                                                        
                                                                                                                                                        
                                                                              
  int main()                                                                  
 {                                                                           
      int base, exponent;                                                     
      cout << "Enter two numbers" << endl;                                    
      cin >> base >> exponent;
      cout << "Your numbers are: " << base << " " << exponent << endl;                                                
      return 0;
  }


is it a compiler issue? I compile and run the code using:

1
2
g++ code.cpp
./a.out


and the output is:
1
2
Enter two numbers
Your numbers are: 0 0



Edit: I figured the issue, it has nothing to do with c++ but with the noevim editor, I compile and run the code from within neovim and it doesn't accept user input. Running a.out from the terminal solves the issue.
Last edited on
Hello waturiuiuiuizifa,

It ran fine with the shell program here.

I do believe, before I check it out, that there is something in lines 3 and 4 that should not be there.

I will let yu know shortly.

Andy
Hi,

Thank you for your help, I figured the issue, it has nothing to do with c++ but with the noevim editor, I compile and run the code from within neovim and it doesn't accept user input. Running a.out from the terminal solved the issue.
Hello waturiuiuiuizifa,

What found is that following #include <iostream> there are unnecessary spaces in the file. Not that this will cause any problems.

I am not familiar with "noevim", but as I understand "g++" the compiler generates ".a" files that are then linked with any other needed files to form the ".exe" program. At least that is my understanding.

Andy
Topic archived. No new replies allowed.