Thread: Point out my error please

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Weak. dra's Avatar
    Join Date
    Apr 2005
    Posts
    166

    Point out my error please

    I thought this would be pretty simple but Windows keeps giving me this message "This application has requested the Runtime to terminate it in an unusal way." Why is this happening?

    Note: At frist I wrote the split function by myself, but when that didn't work, i took one straight from my book, so i can't imagine it being wrong. maybe it's in my main() function?

    Code:
    #include <iostream>
    #include <string>
    #include <vector>
    #include <cctype>
    
    using std::cout;
    using std::cin;
    using std::string;
    using std::vector;
    using std::endl;
    
    vector<string> split( const string& s ){
                   
                   vector<string> ret;
                   typedef string::size_type string_size;
                   string_size i = 0;
                   
                   while ( i != s.size() ){
                         
                         while ( i != s.size() && isspace(s[i]))
                         i++;
                         
                         string_size j = i;
                         while ( j != s.size() && !isspace(s[j]))
                         j++;
                         
                         if ( i != j ){
                              
                              ret.push_back(s.substr(i, j - i));
                              }
                         }
                         return ret;
                         }
    
    int main(){
        
        cout << "Enter a sentence: " << endl;
        string v;
        cin >> v;
        vector<string> sen = split(v);
        
        cout << "The words in the sentence are: " << endl;
        vector<string>::size_type i = 0;
        while ( i != sen.size() ){
              cout << sen[i] << endl;
              i++;
        }
        
        
        }
    EDIT: Problem solved. There was something wrong with the program's logic that i completely overlooked.
    Last edited by dra; 07-10-2005 at 04:00 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copying a binary tree.
    By nempo in forum C++ Programming
    Replies: 3
    Last Post: 04-14-2008, 09:44 PM
  2. Help realy needed
    By ZohebN in forum C++ Programming
    Replies: 2
    Last Post: 04-08-2008, 09:37 AM
  3. Getting a floating point exception
    By SnertyStan in forum C Programming
    Replies: 13
    Last Post: 03-25-2008, 11:00 AM
  4. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  5. floating point binary program, need help
    By ph34r me in forum C Programming
    Replies: 4
    Last Post: 11-10-2004, 07:10 AM