|
Thread: '&'
-
Dec 31st, 2002, 01:11 PM
#1
Thread Starter
Addicted Member
'&'
Nevermind, i didn't want "&" i wanted << so i could join different strings.
Look a few posts below for the fixed code
Last edited by NewGen; Dec 31st, 2002 at 04:39 PM.
-
Dec 31st, 2002, 02:35 PM
#2
Addicted Member
... Ctrl and 7, I'm guessing. You serious?!
Using Visual Studio .NET 2005
-
Dec 31st, 2002, 03:25 PM
#3
Guru
Originally posted by Barguast
... Ctrl and 7, I'm guessing. You serious?!
Shift*
What do you mean, do an '&' sign?
-
Dec 31st, 2002, 04:04 PM
#4
Good Ol' Platypus
If you mean the & (logical and) operator, here's what it does.
Syntax:
answer = num1 & num2
It ANDs the bits in num1 and num2 together. AND means if a bit in num1 is equal to 1 and the same bit in num2 is equal to 1, the output is 1. If not, the output is 0.
For example:
7 & 3 = 3
129 & 7 = 1
129 & 128 = 128
Look at the bits and you'll get it:
111 & 011 = 011
10000001 & 00000111 = 00000001
10000001 & 10000000 = 10000000
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Dec 31st, 2002, 04:23 PM
#5
Thread Starter
Addicted Member
good god people . . .
you think i am that dumb? geeze . . . i mean i though there might be a friggin trick to that operator. Do i have to include a header or c file to use it?
Code:
#include <iostream.h>
int Main()
{
char First_Name[16];
char Last_Name[16];
int Grade_Level;
int Age;
cout<<"What is your First Name?";
cin>>First_Name;
cout<<"What is your Last Name?";
cin>>Last_Name;
cout<<"What grade are you in?";
cin>>Grade_Level;
cout<<"How old are you?";
cin>>Age;
cout<<"Name: " & First_Name & Last_Name & " Grade: " & Grade_Level & " Age: " & Age endl;
return 0;
}
-
Dec 31st, 2002, 04:37 PM
#6
Guru
In that context, replace it with <<.
& is used for string concatenation in VB only. It's completely different in C++.
In C strings (char arrays) you may use strcat to concatenate strings. In C++ strings (std::string) you can use the + operator. In character streams (strstream, or ostream, such as cout) you should use <<.
Code:
cout<<"Name: " << First_Name << Last_Name << " Grade: " << Grade_Level << " Age: " << Age << endl;
-
Dec 31st, 2002, 04:38 PM
#7
Thread Starter
Addicted Member
Ok, i fixed my code:
[code]
#include <iostream.h>
int main()
{
char First_Name[16]
char Last_Name[16]
int Age
cout<<"Please enter your first name.";
cin>>First_Name;
cout<<"Please enter your last name.";
cin>>Last_Name
cout<<"Please enter your age."
cin>>Age
cout<<"Name :" << First_Name << " " <<Last_Name << "Age: " << Age;
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|