Powered by Invision Power Board

 
    Reply to this topicStart new topicStart Poll

> C++ Vectors
United States
RetroXYZ
Posted: Sep 24 2009, 07:34 PM
Quote Post


Standard Member
[*][*]

Group Icon
Group: Members
Posts: 2714
Member No.: 4325
Joined: 27-August 07

Status: (0d) [--]


CODE
std::vector<std::string> explode(std::string str,char delimeter)
{
std::vector<std::string> array (1);
array[0]="";
unsigned int position,index;
position=0;
index=0;
while (position<str.length()-1)
 {
 if (str[position]==delimeter)
  {
  index++;
  array.resize(index+1);
  array[index]="";
  position++;
  }
 array[index]+=str[position];
 position++;
 }
}


I know it's inefficient, and there's probably a better method. It works until it writes the last character, then the application crashes.

This post has been edited by RetroXYZ on Sep 24 2009, 07:34 PM
PMEmail PosterMSN
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

  Topic Options Topic Options Reply to this topicStart new topicStart Poll

 




[ Script Execution time: 0.0278 ]   [ 13 queries used ]   [ GZIP Enabled ]   [ Server Load: 1.39 ]