Thread: Is this "subItem = citem.substr(12,3);"possible?

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    38

    Is this "subItem = citem.substr(12,3);"possible?

    I tried using the sub string funtion that i found on string::substr - C++ Reference

    But it doesn't seem to work. here's the code below, could anyone tell me if I have done something wrong because i'm quite novice at C++.

    Problem line:
    Code:
    subItem = citem.substr(12,3);
    Full code:
    Code:
    #include <iostream>
    #include <vector>
    #include <string>
    
    using namespace std;
    
    int main ()
    {
        
    string subItem;    
    string citem = "0123456789ABCDEFGH";     
    subItem = citem.substr(12,3);
    cout << subItem;
    
    }
    Do i have to do something with .c_str()? I thought that i needed it, but it doesn't seem to help, unless i don't know how to use it.

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    subItem = citem.substr(3,12 );
    is possibly what you meant to write.
    Can't guess better unless I buy a crystal ball .
    Last edited by manasij7479; 10-03-2011 at 01:45 PM.

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    38
    edit:nevermind i figured it out
    Last edited by airesore; 10-03-2011 at 02:05 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question about "std::string::substr"
    By manasij7479 in forum C++ Programming
    Replies: 9
    Last Post: 05-25-2011, 09:41 PM
  2. Replies: 9
    Last Post: 03-31-2009, 04:23 PM
  3. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  4. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM