Mail Archives: djgpp/2000/02/15/09:35:54
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:
This does NOT fix the fact that this is a very bad way to accomplish
your goal. Nor does it fix your possible overrun of the vector. It
does, however, give you working C++ code.
** changes **
1,3c1,3
< #include <iostream.h>
< #include <vector.h>
< #include <stdlib.h>
---
> #include <iostream>
> #include <vector>
> #include <cstdlib>
8c8
< int k; // counter
---
> int k = 0; // counter
17,19c17,19
< cout << word << endl; // SHOULD OUTPUT THE VECTOR
<
< EXIT_SUCCESS; // stdlib.h
---
> for (char *k = word.begin(); k < word.end(); k++)
> cout << *k << endl; // SHOULD OUTPUT THE VECTOR
> return 0;
** resulting code **
#include <iostream>
#include <vector>
#include <cstdlib>
int main()
{
vector < char >word(10); // ten letter word
int k = 0; // 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
}
for (char *k = word.begin(); k < word.end(); k++)
cout << *k << endl; // SHOULD OUTPUT THE VECTOR
return 0;
}
> #include <iostream.h>
> #include <vector.h>
> #include <stdlib.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
> }
>
> I compile using the gxx command at the dos prompt . . . won't work any other
> way, and get a whole lot of iostream errors. there are too many and they are
> too long to try and make sense of. My "hello world"1 programs work with no
> problems. This is just a small test . . . numbers don't work either.
--
Martin Ambuhl mambuhl AT earthlink DOT net
What one knows is, in youth, of little moment; they know enough who
know how to learn. - Henry Adams
A thick skin is a gift from God. - Konrad Adenauer
__________________________________________________________
Fight spam now!
Get your free anti-spam service: http://www.brightmail.com
- Raw text -