Simple Text String

This is a discussion on Simple Text String within the C++ Programming forums, part of the General Programming Boards category; I am trying to make a program that you can enter in a word like: cout<<"What is your name?<<endl; cin>>name; ...

  1. #1
    Registered User BigSter's Avatar
    Join Date
    Nov 2001
    Posts
    47

    Cool Simple Text String

    I am trying to make a program that you can enter in a word like:

    cout<<"What is your name?<<endl;
    cin>>name;
    cout<<"Your Name is "<<name<<" !"<<endl;

    Can anyone help me?
    Thanks

  2. #2
    Unregistered
    Guest
    Code:
    #include <iostream.h>
    
    void main()
    {
        char name[];
    
        cout << "What is your name? ";
        cin >> name;
        cout << "Your name is " << name << ".";
    
        return;
    }

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    164
    Wowowowow! You can't just create a pointer and then use it to input text! That pointer can point on anything!
    // Gliptic

  4. #4
    Unregistered
    Guest
    Erm.

    Make that char name[1];

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    164
    Plenty of space! You can put in a null terminator at least!
    // Gliptic

  6. #6
    Registered User Hoxu's Avatar
    Join Date
    Nov 2001
    Posts
    25
    lol

  7. #7
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    Okay, try this:

    PHP Code:
    #include <iostream>
    #include <string>

    using namespace std;

    int main()
    {
        
    string name;

        
    cout << "What is your name? ";
        
    cin >> name;
        
    cout << "Your name is " << name << "." << endl;

        return 
    0;

    Please, if you spot a mistake, make sure you correct it.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  8. #8
    Registered User Hoxu's Avatar
    Join Date
    Nov 2001
    Posts
    25
    What? A mistake? Haven't seen any

    but hey.. why nobody have told me about that string-library?

  9. #9
    Registered User BigSter's Avatar
    Join Date
    Nov 2001
    Posts
    47
    Hey Thanks

  10. #10
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    There are two views on the string library. One, it hides too much from the programmer and uses confusing syntax with iterators etc. On the other hand, if you understand what is happening behind the scenes by the class methods, then it can make life a lot easier. Because it can make life a lot easier and because you can do a lot by blind trust some people start with the string class so you don't have to monkey with the functions in string.h to manipulate c_style strings. Up to date compilers probably come equipped with the string class, or equivalent, but "older" compilers you can readily come across won't have it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 03:13 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 02:40 AM
  4. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  5. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM

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