Problem with convert and data input

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fullmetalboy
    New Member
    • Jul 2010
    • 2

    Problem with convert and data input

    Hi everybody!

    I'm a newbie to C++ and I need some help to improve my skills in c++.

    *When you make input data "cafe monde" into a string variable, the variable only accept "cafe" and not the white space and "monde". What should I do to retrieve white space, "monde" and "cafe" into the same string variable after data input?

    *Another obstacle I'm facing is to convert char to string. The char also can contain white space or numbers/alphabets. I tried findin' the solution on Internet but I don't really understand the conversation or the code don't work.

    /Fullmetalboy
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Use getline(...) to read an entire line into a string. The normal cin handler uses any white space as the delimiter but by default getline uses end of line.

    There shouldn't be any problem converting characters to a string just assign or add them to the string object.

    Comment

    • fullmetalboy
      New Member
      • Jul 2010
      • 2

      #3
      I already had tried this sourcecode from "]http://www.cplusplus.c om/reference/string/getline/" and it doesn't work. When I execute his sourcecode it just go through without askin' 'bout requestin' for data input. You can read "thank you, " but no data contain in the string variable str.


      "There shouldn't be any problem converting characters to a string just assign or add them to the string object."

      Can you explain with concrete solution by sourcecode? It would be great to understand better.

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        try putting [url]http://bytes.com/topic/c/answers/...[/url] round web links then the forum will actually create a link to the site.

        Did you try that exact example without alteration because it works for me? What compiler are you using?

        Code:
          char a = '7';
          string text;
          text = a;

        Comment

        Working...