Thread: Newbish Question On String Extract

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    1

    Newbish Question On String Extract

    How would I extract a string from an input file? Just need to know what function to use. For example in this line:
    abcdefghijklmnopqrst
    Need to extract "klm" into an array.

  2. #2
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    Use the memberfunction getline in cin. This has been covered several times. Make a Search here

    P.S if you are using MSVC there is a bug in the header files for getline. Solution: a search again
    01000111011011110110111101100100 011101000110100001101001011011100110011101110011 01100100011011110110111001110100 01100011011011110110110101100101 01100101011000010111100101110011 0110100101101110 01101100011010010110011001100101
    Good things donīt come easy in life!!!

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is std::getline().

    string sInput;
    std::getline(cin, sInput);
    size_t nFind = 0;

    if ((sInput.find("klm")) != sInput.npos)
    string sKey = sInput.substr(nFind, 3);

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Next Question...
    By Azmeos in forum C++ Programming
    Replies: 3
    Last Post: 06-06-2003, 02:40 PM
  5. String array question
    By gogo in forum C++ Programming
    Replies: 6
    Last Post: 12-08-2001, 06:44 PM