adding space

This is a discussion on adding space within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> using namespace std; int main() { int a,b,c; cout<<"enter a number"; cin>>a; cout<<"enter a number"; cin>>b; cout<<"enter ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    26

    adding space

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	int a,b,c;
    	cout<<"enter a number";
    	cin>>a;
    	cout<<"enter a number";
    	cin>>b;
    	cout<<"enter a number";
    	cin>>c;
    	cout<<a <<a*a <<endl;
    	cout<<b <<b*b <<endl;
    	cout<<c <<c*c <<endl;
    	return 0;
    }
    how do i add a space between the number and the squared number??? thank you

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    Code:
    cout << a << " " << a*a << endl;

  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    i would use single quotes:

    cout<<a<<' '<<a*a;
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Using the double quotes is better, because you need them anyways if you're going to use a two or more character delimiter.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    you can use single quotes for up to and including two characters...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Except for the fact that when you cout a 2-character constant surrounded by single quotes, it treats it like an integer.

    Code:
    #include <iostream>
    
    int main( void )
    {
      std::cout<<"a"<<', '<<"b"<<std::endl; // Delimeter is a comma and a space
    }
    This code outputs a11296b. 11296 is the value of (','<<8) | '&nbsp;'.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  7. #7
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    oh really? I didn't know that... i only use it for escape sequences and spaces, etc.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  8. #8
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    But an escape sequence is only one character. It just looks like two.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Out of space when compiling kernel
    By NuNn in forum Linux Programming
    Replies: 3
    Last Post: 04-01-2009, 03:43 PM
  2. SVN Import Causes Crash
    By Tonto in forum Tech Board
    Replies: 6
    Last Post: 11-01-2006, 03:44 PM
  3. Replies: 12
    Last Post: 05-17-2003, 06:58 AM
  4. adding a space to a string
    By watshamacalit in forum C Programming
    Replies: 1
    Last Post: 01-01-2003, 12:01 PM

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