Having Spaces in Input

This is a discussion on Having Spaces in Input within the C++ Programming forums, part of the General Programming Boards category; when inputting character string values using cin>>, is it possible to put any spaces between words?...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    72

    Having Spaces in Input

    when inputting character string values using cin>>, is it possible to put any spaces between words?

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    Yeah...try cin.getline()


    Code:
    #include <iostream>
    using std::cout;
    using std::cin;
    using std::endl;
    
    int main(void){
    
    	const int ARRAYLENGTH = 50;
    	char buff[ARRAYLENGTH];
    
    	cout << "Type something with spaces" << endl;
    
    	cin.getline(buff,ARRAYLENGTH-1);
    
    	cout << "You wrote " << buff << endl;
    	return 0;
    
    }
    Last edited by Fordy; 09-15-2002 at 11:35 AM.

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    Err...look above

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    72
    I get a qualifier 'std' is not a class or namespace name error, whats wrong

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    Hmm...maybe your compiler is old....substitute

    Code:
    #include <iostream>
    using std::cout;
    using std::cin;
    using std::endl;
    for

    Code:
    #include <iostream.h>
    If this works, great, but seriously consider a new compiler! There are loads free on the web for download

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 03:13 PM
  2. still problems with ceasar shift
    By trevordunstan in forum C Programming
    Replies: 2
    Last Post: 09-14-2008, 01:49 AM
  3. Basic C input output program help
    By trevordunstan in forum C Programming
    Replies: 2
    Last Post: 01-27-2008, 05:41 PM
  4. Custom Made Safe Input Function
    By Beast() in forum C Programming
    Replies: 6
    Last Post: 08-21-2004, 10:19 PM
  5. fgets - user input including spaces
    By MethodMan in forum C Programming
    Replies: 24
    Last Post: 03-12-2004, 06:36 PM

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