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

This is a discussion on Is this "subItem = citem.substr(12,3);"possible? within the C++ Programming forums, part of the General Programming Boards category; I tried using the sub string funtion that i found on string::substr - C++ Reference But it doesn't seem to ...

  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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    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.
    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 !



  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, 07: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, 06:59 AM

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