'bout strings.. please help:(

Discussion in 'C++' started by Jazel, Oct 1, 2010.

  1. Jazel

    Jazel New Member

    Joined:
    Sep 23, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Davao city[Philippines]
    ..how can i display what I've just input, including space?????
    example
    Name: Jazel Juarez
    ---> I've tried it but only the first word did print out
    -----
    char question[] = "Name: ";

    char urname[80];
    cout<<Name;
    getline(cin,question);
    cin>>urname;
    cout<<urname<<"!";
    -->the program above... have 2 errors
    1.declaration syntax error
    2. the function getline should have prototype
    please help me thanks!
     
  2. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    19
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    http://www.techgeek.in
    Yes, Itz better you should first delete the pointer and the realloc.... But if dnt delete then also there will be no problem because the OS Memory management will do the work 4 u...
     
  3. ashken

    ashken New Member

    Joined:
    Oct 22, 2010
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    use the gets() function which is found in the header file cstdio

    Code:
    #include <iostream>
    #include <cstdio>
    
    using namepace std;
    
    int main(){
    
     char names[80];
     cout <<"Please enter your two names"<<"\n";
     gets(names);
     cout<<"Your name is "<<names;
    }
    
    or you can still use getline()

    Code:
    #include <iostream>
    
    int main(){
    
     char names[80];
     cout <<"Please enter your two names"<<"\n";
     cin.getline(name,80);
     cout<<"Your name is "<<names;
    }
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice