| | |
need help for this code
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Here is some sample code which may be of use to you:
You might not be able to use stringstreams to separate your sentence into bits...
output
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <algorithm> #include <ctime> #include <string> #include <sstream> using namespace std; int main() { string line; cout << "Please insert the words that you want to scramble" << endl; getline ( cin, line, '\n' ); string array[100]; stringstream ss ( line ); string word; string newLine = ""; int i = 0; while ( ss >> word ) { array[i] = word; i++; } char ans; do { cout << "\nReshuffle (Y/N)" << endl; cin >> ans; srand ( unsigned ( time ( NULL ) ) ); random_shuffle ( array, array + i ); //print shuffled sentence cout << "\n"; for ( int j = 0 ; j < i; j++ ) { cout << array[j] << " "; } }while ( ans != 'N' ); system ( "PAUSE" ); return 0; }
You might not be able to use stringstreams to separate your sentence into bits...
output
C++ Syntax (Toggle Plain Text)
Begin file creation Please insert the words that you want to scramble HELLO, I AM A FOOL! RESHUFFLE (Y/N) Y A FOOL! HELLO, I AM RESHUFFLE (Y/N) Y I AM FOOL! A HELLO, RESHUFFLE (Y/N) Y A HELLO, AM I FOOL! RESHUFFLE (Y/N) Y I FOOL! HELLO, A AM RESHUFFLE (Y/N) Y AM I FOOL! HELLO, A RESHUFFLE (Y/N)
Last edited by iamthwee; Sep 25th, 2008 at 2:39 pm.
*Voted best profile in the world*
![]() |
Similar Threads
- Code 19 Registry Error (Windows NT / 2000 / XP)
- Why won't this code work? (VB.NET)
- Need help with DirectX code (C)
- Tutorials & Code Submissions - Questions? (DaniWeb Community Feedback)
- Some Basic Code Hopefully (Help Needed) (HTML and CSS)
Other Threads in the C++ Forum
- Previous Thread: Opening and closing a file very often?
- Next Thread: Delete all leaf node in BST
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






