Thread: string question.

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    47

    string question.

    how could i achieve the following.

    Code:
        string monthChoice, dateChoice;
        int dayChoice, yearChoice;
    
        cout<<"enter month";
        cin>>monthChoice;
        cout<<"enter day";
        cin>>dayChoice;
        cout<<"enter year";
        cin>>yearChoice;
    
        dateChoice = (monthChoice + " " + dayChoice + ", " + yearChoice);

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If youwant to produce a string, then you could use "stringstream" from the <strstream> include-file.

    Just output your components to the stringstream, then use the stringstream as an input to a string.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    47
    could you possibly give me an example?.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, but if you search for stringstream in the forum, I'm pretty sure you can find the example I posted a few days ago, and your searching is just as easy as mine.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> If youwant to produce a string, then you could use "stringstream" from the <strstream> include-file.

    Note that stringstreams are in <sstream>.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Reusing a string pointer question
    By chiefmonkey in forum C++ Programming
    Replies: 3
    Last Post: 05-06-2009, 04:53 PM
  3. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  4. String array question
    By gogo in forum C++ Programming
    Replies: 6
    Last Post: 12-08-2001, 06:44 PM