-
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
-
Code:
cout << a << " " << a*a << endl;
-
i would use single quotes:
cout<<a<<' '<<a*a;
-
Using the double quotes is better, because you need them anyways if you're going to use a two or more character delimiter.
-
you can use single quotes for up to and including two characters...
-
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) | ' '.
-
oh really? I didn't know that... i only use it for escape sequences and spaces, etc.
-
But an escape sequence is only one character. It just looks like two. ;)