problem with cin>> in c++ using code blocks

Status
Not open for further replies.
Aug 15, 2014
3
0
4,510
hello i am new to c++ and i am using code blocks to learn it. i typed the following code:
#include <iostream>
using namespace std;

int main() {
int x=1;
int number;

while (x<=5){
cin >> number;
x++;
}

return 0;
}

the cin>> doesn't seem to work i.e the console box appears but i can't input any values

please help
 
Solution


Code::Blocks is an IDE, not a compiler. You should have chosen a compiler infrastructure when you created the project. It should support all the major ones on Windows including MinGW, MSVC++, Borland C++, and Intel C++.

I tested your code using ICPC (Intel's C++ compiler), clang++, and g++ on Linux and all worked well. I also tested it using MSVC++ on Windows and it also worked...
Aug 15, 2014
3
0
4,510




All i know is that according to the code that i've written above i'm supposed to type 5 numbers on the blank black box or screen (is it called the console box or application) until the box displays something like this:

process returned 0 <0x0> execution time : 5.59 s
press any key to continue

All i see is the black screen appearing and displaying " press any key to continue " even before i have typed any numbers
 

Ijack

Distinguished
Are you absolutely sure that you have typed the code exactly as here? It looks fine and I have pasted it and compiled it to check. It does exactly what you want it to.

Which operating system and C++ compiler are you using (not that it should matter)?
 
Aug 15, 2014
3
0
4,510


yes i have typed the code exactly as here. i am using windows 7 and the compiler is Code::Blocks
 

Pinhedd

Distinguished
Moderator


Code::Blocks is an IDE, not a compiler. You should have chosen a compiler infrastructure when you created the project. It should support all the major ones on Windows including MinGW, MSVC++, Borland C++, and Intel C++.

I tested your code using ICPC (Intel's C++ compiler), clang++, and g++ on Linux and all worked well. I also tested it using MSVC++ on Windows and it also worked as expected

 
Solution

Pinhedd

Distinguished
Moderator


Some C compilers are a bit pedantic about the main entry point. This is usually accompanied by a warning though. I know that C++ is significantly more flexible but I wanted to test it to be sure.

`x >= 5` is a good possibility though
 
Status
Not open for further replies.