Mail Archives: djgpp/2000/02/15/07:09:02
In article <20000214230117 DOT 03930 DOT 00001183 AT ng-ce1 DOT aol DOT com>, kngaru AT aol DOT com (KNGARU) wrote:
>sort of . . .
>This doesn't work, granted there may be some problems to it, but I keep getting
>errors I have no clue what to do with.
>Here's the program:
>#include <iostream.h>
>#include <vector.h>
>#include <stdlib.h>
For a start, change iostream.h to iostream and vector.h to vector (drop the
h).
>
>int main()
>{
>vector<char> word(10); //ten letter word
>int k; //counter
>char letter; //no need
>while(cin>>letter) //input letter by letter . . . one step at a time
>{
>word[k]=letter; //puts the letter in the current index of the vector
>k++; //increases counter
>}
>cout<<word<<endl; //SHOULD OUTPUT THE VECTOR
>
>EXIT_SUCCESS; //stdlib.h
>}
You are trying to use a vector as a string. This might be a good way to learn
to use vectors, but string is already there.
I guess the errors you are getting are about the operator ostream<<vector
<char> being undefined.
This is correct. If you want to output a vector, you will have to provide your
own operator, because the compiler simply does not know how to output a
vector. Maybe you should wait with this and take one step after the other.
What you can do, is output the vector bit by bit, like so:
for (int i=0; i<word.size(); i++)
cout << word[i];
This will work because the compiler knows how to output a char.
--
Manni
- Raw text -