variable/string trouble

This is a discussion on variable/string trouble within the C++ Programming forums, part of the General Programming Boards category; Hi, I am creating a program to help me memorize stuff but I need a variable that will hold full ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    1

    Question variable/string trouble

    Hi,
    I am creating a program to help me memorize stuff but I need a variable that will hold full sentences with spaces.
    Also i want to be able to check weather the user input macthes the correct answer.
    Thank You.

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,304
    std::string is what you want. You use the == operator to compare them (case-sensitive)
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Depending on your exact usage, std::vector<std::string> may be more appropriate.
    (For example, what if the user enters an exra whitespace somewhere.)

    Comparing would then need a loop, though.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-25-2011, 10:33 PM
  2. Replies: 10
    Last Post: 03-28-2010, 01:35 AM
  3. Having trouble converting a variable
    By KasMage in forum C++ Programming
    Replies: 6
    Last Post: 07-14-2008, 03:43 PM
  4. Replies: 12
    Last Post: 10-14-2003, 10:17 AM
  5. Trouble with a class variable
    By TravisDane in forum C++ Programming
    Replies: 9
    Last Post: 12-07-2002, 11:59 PM

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