C++ question

This is a discussion on C++ question within the C++ Programming forums, part of the General Programming Boards category; I wanna make a program which can print one line and then it will wait for the signal(space bar's input), ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    101

    C++ question

    I wanna make a program which can print one line and then it will wait for the signal(space bar's input), after that, it will print the second line.

    eg
    1.
    aaaaaaa
    (wait)

    2.
    aaaaaaa
    (space_bar pressed)

    3.
    aaaaaaa
    bbbbbbb
    (wait)

    4.
    ...


    thx!!~

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Code:
    #include <iostream>
    #include <conio.h>
    using std::cout;
    using std::endl;
    
    
    int main(void){
    char c;
    	while(c = getch()){
    		if(c == ' ')cout << "aaaaaaa" << endl;
    		else if(c == '\r')break;
    	}
    return 0;
    }
    This prints a line every time you press the space bar. Press enter to quit

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 03:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21