![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Oct 2005
Posts: 84
Rep Power: 4
![]() |
How to clear console buffers
Hi
i have to take input from user in console using Console.Read() and Console.Readline() functions but whenever i use Console.Readline() before Console.Read() , the Console.Read() funtion does not execute plz help eg using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
int x=Console.Read();
string str = Console.ReadLine();
int z= Console.Read();
}
}
}
__________________
"You're good... but me, I'm magic" |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
First of all, Console.Read is used for reading single characters, not tokens. Read the int in using int x = int.Parse(Console.ReadLine()); .
The reason the second Read didn't seem to be executing was that you were entering one on each line: when you typed an integer, the first function read the character... then the next read the rest of the line. The string you typed was read partially by the third, and then dropped when your program finished. |
|
|
|
|
|
#3 | |
|
Programmer
Join Date: Oct 2005
Posts: 84
Rep Power: 4
![]() |
Quote:
i have also tried to do this char x=(char)Console.Read();
string str = Console.ReadLine();
char z = (char)Console.Read();
__________________
"You're good... but me, I'm magic" |
|
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Try typing:
x Something m |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Making a C app run without a console | ibbrowne3 | C | 7 | Nov 21st, 2006 12:40 PM |
| Manipulating the console using Windows API | rup | C++ | 2 | Nov 17th, 2006 1:04 PM |
| Simple question, I think? | Phonetic | Bash / Shell Scripting | 3 | Nov 15th, 2006 3:31 AM |
| The Black Art of Video Game Console Design | lostcauz | Book Reviews | 0 | Apr 26th, 2006 7:31 PM |
| Clear screen with Java | Eric the Red | Java | 9 | Feb 22nd, 2006 10:28 PM |