HELP WHIT-What is your name? Hallo _____

This is a discussion on HELP WHIT-What is your name? Hallo _____ within the C++ Programming forums, part of the General Programming Boards category; Ok im a begginer(started yesterday)and I have been working whit the variable int I want to do a program that ...

  1. #1
    NewBoy
    Guest

    HELP WHIT-What is your name? Hallo _____

    Ok im a begginer(started yesterday)and I have been working whit the variable int

    I want to do a program that asks for your name and then greets you.I have this-

    Code:
    #include <iostream.h>
    #include <stdio.h>
    int main(int nNumberofArgs, char* pzArgs[])
    {
        string name;
    	cout << "What is your name?";
    	cin >> name;
    	cout << "hallo,";
    	cout << name;
        return 0;
    }
    But it doesent work
    When I work whit the variable int and put it in My code(Im using MicrosoftVisual6.0) "int" turns blue but when I put "string it doesent turn blue=\

    WHATS WRONG ? ? ? ?

    Thanks in advance

    &#91;code]&#91;/code]tagged by Salem

  2. #2
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Borrow a good C++ book from your local library.
    Perhaps reading the FAQ also helps.

    If not, include <string> to your sourcefile, and add the line "using namespace std;" somewhere.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  3. #3
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    I can't figure out what you're trying to do with this:

    int main(nNumberofArgs, char* pzArgs[])


    Just make it

    int main()


    It also wouldn't hurt to read this.
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    First, get rid of the "arguments" in 'int main()'. They're unnecessary here.

    Second, 'string' is not a "member" of <iostream> but rather of <string>.

    Third, your question sounds "panicky". Read the FAQ. Panicky questions don't play well on the Board.

    Fourth, learn to use code tags (see above). In your case, it isn't a big deal, but you're going to get farther if you learn to use them.

    Code:
    #include <iostream>
    #include <string>
    #include <cstdlib>    // system call
    
    inline void pause() { system("PAUSE"); }
    
    int main(void)
    {
    std::string name;
    
    std::cout << "Enter your name: -> ";
    std::cin >> name;
    
    std::cout << "\nHello, " << name << "!" << std::endl << std::endl;
    
    pause();
    return 0;
    }
    Research the difference between <iostream.h> and <iostream>, et. al. These have to do with the C++ Standard and there are a ton of references on this site that deal with it.

    P.S. Darn it, Kermi, I've got to learn to type faster!

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  5. #5
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380

    Re: HELP WHIT-What is your name? Hallo _____

    Originally posted by NewBoy
    When I work whit the variable int and put it in My code(Im using MicrosoftVisual6.0) "int" turns blue but when I put "string it doesent turn blue=\
    MSVC++ colors keywords blue (by default)... "string" is not a keyword

  6. #6
    NewBoy
    Guest
    But in the book I have(C++ for Dummies)it says that int,float,double,char,string,and long are variables.
    And when I put any of them in the code they turn blue but string doesent.

    So what is the variable for when I want the computer to remember a word?

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >But in the book I have(C++ for Dummies)it says that int,float,double,char,string,and long are variables.
    No, all of the above are data types you use data types to define variables which contain the appropriate data. The reason string isn't blue is because it is a user defined type found in a library, not a built-in type defined by the language itself. Your compiler doesn't color the names of user defined types because they are identifiers, not keywords.

    >So what is the variable for when I want the computer to remember a word?
    You can either use an array of characters terminated by the nul ('\0') character, or a user defined type like std::string.

    -Prelude
    My best code is written with the delete key.

  8. #8
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    Originally posted by NewBoy
    But in the book I have(C++ for Dummies)it says that int,float,double,char,string,and long are variables.
    Those are types of variables... a variable has to have a type so that the computer knows how to handle it and how much memory to allocate for it. A variable of type int (int x;) is a variable that can hold ints (integers). A char holds 1-byte values (commonly used for single characters because 1-byte = 8-bits = 256 possible values, which works nicely for the latin character set). A float holds single-precision floating point variables (like 1.2). A double holds double-precision floating point variables (like 3.14). A string holds null-terminated arrays of characters.

    Uhm... you may want to get some beginner C++ books.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adding uint_64 whit uint_32
    By isato in forum C Programming
    Replies: 4
    Last Post: 06-12-2009, 06:45 PM
  2. Sorting whit MPI
    By isato in forum C Programming
    Replies: 0
    Last Post: 03-03-2009, 09:38 AM

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