| | |
Splitting words from string into character array
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Feb 2005
Posts: 4
Reputation:
Solved Threads: 0
So Im trying to write some code that takes a chunk of text, splits it up into words, then puts these words into an array. What I have is:
So in that while loop I want to take the string "buf" and put it into an array. Thus the result is an array of strings containing every word in the paragraph. This is where I feel like an idiot.
I have tried a few ways using string streams and converting strings to char arrays etc, but nothing will work for me. I have a feeling that this has to do with multidimensional arrays and pointers, but my searches have been fruitless.
Thanks in advance!
C++ Syntax (Toggle Plain Text)
string buf; stringstream ss(database); // database is my chunk of text while (ss >> buf) // Tokenize when whitespace met { ??? }
So in that while loop I want to take the string "buf" and put it into an array. Thus the result is an array of strings containing every word in the paragraph. This is where I feel like an idiot.
I have tried a few ways using string streams and converting strings to char arrays etc, but nothing will work for me. I have a feeling that this has to do with multidimensional arrays and pointers, but my searches have been fruitless.
Thanks in advance!
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
C++ Syntax (Toggle Plain Text)
#include <vector> #include <boost/tokenizer.hpp> #include <string> #include <vector> #include <iostream> using namespace std; using namespace boost; int main() { string str = "The boost tokenizer library provides a flexible " "and easy to use way to break of a string or other " "character sequence into a series of tokens.\n" "Here is a simple example that will break up a " "paragraph into words.\n"; tokenizer<> toker( str ); vector<string> words( toker.begin(), toker.end() ) ; cout << "there are " << words.size() << " words\n" ; cout << "words[6]: " << words[6] << '\n' ; }
Last edited by vijayan121; Jun 16th, 2007 at 11:29 pm.
![]() |
Similar Threads
- Copying words into an array of char ?!? (C)
- How to work with digits when they are characters in a string (C)
- How to flip bits (C)
- Character Array to character pointer. (C)
- String class help (Java)
- CS First Year student, help with arrays (C++)
- Help with folding a character array please (C)
- How do I create a program using an Array ? (C++)
Other Threads in the C++ Forum
- Previous Thread: Linked lists
- Next Thread: database and form security
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






