Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi all
I need to get an input from the keyboard in my c++-prog. This can by done with getch(), cin or scanf, i know. The programm executs fine until i should enter the char. But then, NOTHING HAPPENS!! The programm is just ignors what im typing on my keyboard and waits and waits and waits!! It doesnt matter which of the methods i use, my keystrokes just arent remarked by the programm.
Why does my computer do this to me? I have absolutely no clue. Any help will be greatly appreciated.rde

what are you trying to do after you get the input character
is the input an array, are you trying to get the data while in a loop???
give more info

Buying a newer faster computer might solve the problem!
Why dont you post your code so we can see you're trying to do..

The prog is really very simple. Its not the prog i try to write, but its the easiest way to use cin(or equivalent) i can think of and its enough to explain my problem.
If I run the prog it prints "Enter a character" on the screen (as it should) and waits for an input. When i try to make an input, nothing happens, absolutely nothing. The computer just goes on waiting for an input. All i can do then is terminate the prog.rde
------
#include
#includevoid main()
{char c;
cout > c;
cout endl endl c endl;
getch();
}-----------Code end------------------

Damn forum. Is there a way to post code correctly? I used substitute signs instead.
#include [conio.h]
#include [iostream.h]void main()
{char c;
cout [[ "Enter a character" [[ endl;
cin ]] c;cout [[ endl [[ endl [[ c [[ endl;
getch();
}

Got this to work...?
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(int argc, char *argv[])
{
char c;
std::cout << "Please enter a character: " << endl;
cin >> c;
cout << "Your char is: " << c << endl;
system("PAUSE");
return 0;
}

No. I get some compiling errors.Line 4:
Namespace name expectedLine 9:
Qualifier 'std' is not a class or namespace name
Statement missing;There is no spelling mistake, i checked it more than once. Since i never used namespaces before, i dont know exactly how they work and whats wrong.
rde

Sorry, that was sloppy. This example will clear it up.. This is basically just saying I using classes from the standard lib.
the system("PAUSE"); is to keep the window open.
#include <iostream>
int main(int argc, char *argv[])
{
char c;
std::cout << "Please enter a character: " << std::endl;
std::cin >> c;
std::cout << "Your char is: " << c << std::endl;
system("PAUSE");
return 0;
}

Isn't it standard now to use the namespace?
At least when I try to compile under Linux with the new gcc and do not have the namespace listed... it bombs on me.
-
No reason the code above would not work unless its a compiler problem or typo when you are transcribing it.
IR

Yeah, it is. I get bombed too.. You have to either declare it at the top or when you call a method. I dont really use C++ anymore, but I think iostream is a deprecated class...?

I don't believe iostream is depreciated, it is what cin and cout and std are defined in.
This code works fine in the following compilers (VC++, BCB, BCC5.5, OpenWatcom, CodeWarrior):
#include <iostream>
#include <conio.h>
using namespace std;
int main(void)
{
char c;
cout << "Please enter a character: " << endl;
cin >> c;
cout << "Your char is: " << c << endl;
getch();
return 0;
}
Chi Happens

Ok, sorry to sound COMPLETELY ignorant here, but ive been looking through a number of posts on C++, and I'd like to know what this endl; statement is? Please! :-)

![]() |
Vb 6.0 help
|
installing .NET 2003: vdt...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |