www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/02/15/09:35:54

Message-ID: <38A94948.4985420D@earthlink.net>
From: Martin Ambuhl <mambuhl AT earthlink DOT net>
Organization: Nocturnal Aviation
X-Mailer: Mozilla 4.7 [en] (Win95; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Vector problem
References: <20000214230117 DOT 03930 DOT 00001183 AT ng-ce1 DOT aol DOT com>
Lines: 98
NNTP-Posting-Host: 209.246.74.122
X-Complaints-To: abuse AT earthlink DOT net
X-Trace: newsread2.prod.itd.earthlink.net 950618424 209.246.74.122 (Tue, 15 Feb 2000 04:40:24 PST)
NNTP-Posting-Date: Tue, 15 Feb 2000 04:40:24 PST
X-ELN-Date: Tue Feb 15 04:40:24 2000
Date: Tue, 15 Feb 2000 12:40:24 GMT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie 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:

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019