Thread: Word Jumbling

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    You can do what you want very easily with the C++ Standard Template Library:
    Code:
    #include<iostream>
    #include<string> begin(), end()
    #include<algorithm> //random_shuffle()
    #include<ctime> //time()
    
    using namespace std;
    
    int main()
    {
    	srand(time(0));
            
            //shuffle the whole string:
    	string str = "hello";
    	random_shuffle(str.begin(), str.end());
    	cout<<str<<endl;
    
            //shuffle part of the string:
    	str = "hello world";
    	random_shuffle(&str[6], str.end()); //only shuffles 'world'
    	cout<<str<<endl;
    
    	return 0;
    }
    Last edited by 7stud; 11-13-2005 at 07:05 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  3. please help with binary tree, urgent.
    By slickestting in forum C Programming
    Replies: 2
    Last Post: 07-22-2007, 07:55 PM
  4. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  5. Wrong Output
    By egomaster69 in forum C Programming
    Replies: 7
    Last Post: 01-28-2005, 06:44 PM