Original Post
🔒 Locked
An array of strings
Advertisement
You could do something like this:
Using a struct or class approach, you could make a function that dynamically allocated the memory for the sentence if you need more than 100 or if the sentences are much different in length.
I''ve also heard of something called STL which has a string class. I don''t know anything about that though...
My Geekcode: "GCS d s: a14 C++$ P+(++) L+ E-- W+++$ K- w++(+++) O---- M-- Y-- PGP- t X
R- tv+ b++ DI+(+++) D- G e* h!"
Decode my geekcode!
Geekcode.com
Visit our web site:
Asylum Entertainment
|
Using a struct or class approach, you could make a function that dynamically allocated the memory for the sentence if you need more than 100 or if the sentences are much different in length.
I''ve also heard of something called STL which has a string class. I don''t know anything about that though...
My Geekcode: "GCS d s: a14 C++$ P+(++) L+ E-- W+++$ K- w++(+++) O---- M-- Y-- PGP- t X
R- tv+ b++ DI+(+++) D- G e* h!"
Decode my geekcode!
Geekcode.com
Visit our web site:
Asylum Entertainment
#include < string >
#include < vector >
using namespace std;
int main(void)
{
vector< string > sentence;
// then you could set the size for the number of words
sentence.resize(10); //or whatever...
// then say ...
sentence[0] = "HAPPY";
sentence[1] = "FISH";
sentence[2] = "ARE";
sentence[3] = "YUMMY.";
// etc, etc...
// got it?
}
By the way, this IS using the STL that ziplux mentioned...
happy coding...?!?
Briar->LoDeran();
Edited by - BriarLoDeran on December 5, 2000 8:35:18 PM
Here''d be an STL way to do it (although if you don''t know about arrays, it''s probably over your head):
There you have it. There are some issues using a vector in this way, namely that the vector will have to recopy itself every time it overgrows its bounds. It''s really more of a list of word--you could substitute "list" for "vector" and everything would work. However, if you''re going to USE this container to find, say, the odd words in the sentence or word #5, then you want a vector. A change might be to read it in to a local list in the function, then copy the list into a vector and return it.
Hope it''s not way over your head.
|
There you have it. There are some issues using a vector in this way, namely that the vector will have to recopy itself every time it overgrows its bounds. It''s really more of a list of word--you could substitute "list" for "vector" and everything would work. However, if you''re going to USE this container to find, say, the odd words in the sentence or word #5, then you want a vector. A change might be to read it in to a local list in the function, then copy the list into a vector and return it.
Hope it''s not way over your head.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement