On May 3, 2:53*am, nick_keighley_nos...@hotmail.com wrote:
> On Thursday, May 3, 2012 8:52:40 AM UTC+1, nick_keigh...@hotmail.com wrote:
> > On Thursday, May 3, 2012 8:38:31 AM UTC+1, Ian Collins wrote:
> > > On 05/ 3/12 07:25 PM, Charles Wilson wrote:
>
> > > > I believe that my problem is in how I am doing my C++ strings. But I
> > > > am not sure. *Can someone point me in the right direction. Thank you
>
> > > > #include<iomanip>
> > > > #include<iostream>
> > > > #include<fstream>
> > > > #include<cstring>
> > > > using namespace std;
>
> > I can't believe how long it took me to find the bug!
>
> > RULE 1: DON'T USE "using namespace std;"
> > you'll find std::string isn't defined
>
> > > > int main()
> > > > {
> > > > *struct{int chronum;string pname;int next;}//makes structure box with C
> > > > ++ style string
> > > > * * * * *plist[50],temp;//give the number of colmns
> > > > *int n=0,end,maxindex,i;
> > > > *ifstream fin;
> > > > *ofstream fout;
> > > > *fin.open("pres.dat");
> > > > *fout.open("hw7.dat");
> > > > *fin>>plist[n].pname;//inputs president name into list
> > > > *while(!fin.eof())
> > > > * * * * *{
> > > > * * * * * plist[n].chronum=n+1;//assigns chronum to presidents as inputed.
> > > > * * * * * n++;//tracks current president
> > > > * * * * * fin>>plist[n].pname;
> > > > * * * * *}
> > > > *for(end=n-1;end>0;end--)//it seems to input all on the first past and
> > > > than removes one of end each time.
>
> > what?
>
> > > > * * * * *{
> > > > * * * * * maxindex=0;
> > > > * * * * * for(i=1;i<=end;i++)
>
> > > > * * * * * * * * *if(plist[i].pname>plist[maxindex].pname)
> > > > * * * * * * * * * * * * *maxindex=i;
> > > > * * * * * temp=plist[maxindex];
> > > > * * * * * plist[maxindex]=plist[end];
> > > > * * * * * plist[end]=temp;
> > > > * * * * *}
> > > > *//cout.setf(ios::fixed);
> > > > *//cout.setf(ios::showpoint);
> > > > *//cout.precision(2);
> > > > *//cout<
> > > *return 0;
> > > > }
>
> > > What compile errors do you get? *The code looks legal.
>
> > cut down version of the code:-
>
> > 1>w:\project\bin\quick\wilson.cpp(10) : error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
>
> sorry, the offending line is
>
> *fin>>plist[n].pname;
How?
|