Results 1 to 7 of 7

Thread: '&'

  1. #1

    Thread Starter
    Addicted Member NewGen's Avatar
    Join Date
    Nov 2002
    Location
    olathe, ks
    Posts
    152

    '&'

    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.

  2. #2
    Addicted Member
    Join Date
    Nov 2002
    Posts
    195
    ... Ctrl and 7, I'm guessing. You serious?!
    Using Visual Studio .NET 2005

  3. #3
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    Originally posted by Barguast
    ... Ctrl and 7, I'm guessing. You serious?!
    Shift*

    What do you mean, do an '&' sign?

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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)

  5. #5

    Thread Starter
    Addicted Member NewGen's Avatar
    Join Date
    Nov 2002
    Location
    olathe, ks
    Posts
    152

    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;
    }

  6. #6
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    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;

  7. #7

    Thread Starter
    Addicted Member NewGen's Avatar
    Join Date
    Nov 2002
    Location
    olathe, ks
    Posts
    152
    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
  •  



Click Here to Expand Forum to Full Width