I just want get this portion of the code to compile.

C

Charles Wilson

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;

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.
{
maxindex=0;
for(i=1;i<=end;i++)

if(plist.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<<plist.chronum<<plist.pname<<endl;
return 0;
}
 
I

Ian Collins

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;

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.
{
maxindex=0;
for(i=1;i<=end;i++)

if(plist.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<<plist.chronum<<plist.pname<<endl;
return 0;
}


What compile errors do you get? The code looks legal.
 
C

Charles Wilson

Why <cstring>?
oops typo

#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

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.
{
maxindex=0;
for(i=1;i<=end;i++)

if(plist.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<<plist.chronum<<plist.pname<<endl;
return 0;
}
 
G

Guest

On 05/ 3/12 07:25 PM, Charles Wilson wrote:

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.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)
 
C

Charles Wilson

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;
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.
           {
            maxindex=0;
            for(i=1;i<=end;i++)
                   if(plist.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<<plist.chronum<<plist.pname<<endl;
return 0;
}


What compile errors do you get?  The code looks legal.



This is what I get


[cwilson@orion Hw7]$ gcc hw7.cpp
/tmp/ccN2xrWu.o: In function `main::._84::._84()':
hw7.cpp:(.text+0x15): undefined reference to `std::basic_string<char,
std::char_traits<char>, std::allocator<char> >::basic_string()'
/tmp/ccN2xrWu.o: In function `main::._84::~._84()':
hw7.cpp:(.text+0x31): undefined reference to `std::basic_string<char,
std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccN2xrWu.o: In function `main::._84::eek:perator=(._84 const&)':
hw7.cpp:(.text+0x65): undefined reference to `std::basic_string<char,
::eek:perator=(std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&)'
/tmp/ccN2xrWu.o: In function
`__static_initialization_and_destruction_0(int, int)':
hw7.cpp:(.text+0xa1): undefined reference to
`std::ios_base::Init::Init()'
/tmp/ccN2xrWu.o: In function `__tcf_0':
hw7.cpp:(.text+0xe4): undefined reference to
`std::ios_base::Init::~Init()'
/tmp/ccN2xrWu.o: In function `main':
hw7.cpp:(.text+0x1ee): undefined reference to
`std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream()'
hw7.cpp:(.text+0x1fa): undefined reference to
`std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream()'
hw7.cpp:(.text+0x210): undefined reference to
`std::basic_ifstream<char, std::char_traits<char> >::eek:pen(char const*,
std::_Ios_Openmode)'
hw7.cpp:(.text+0x232): undefined reference to
`std::basic_ofstream<char, std::char_traits<char> >::eek:pen(char const*,
std::_Ios_Openmode)'
hw7.cpp:(.text+0x260): undefined reference to
`std::basic_istream<char, std::char_traits<char> >&
(std::basic_istream<char, std::char_traits<char> >&,
hw7.cpp:(.text+0x2bc): undefined reference to
`std::basic_istream<char, std::char_traits<char> >&
(std::basic_istream<char, std::char_traits<char> >&,
hw7.cpp:(.text+0x2cf): undefined reference to `std::basic_ios<char,
std::char_traits<char> >::eof() const'
hw7.cpp:(.text+0x406): undefined reference to
`std::basic_ofstream said:
::~basic_ofstream()'
hw7.cpp:(.text+0x422): undefined reference to
`std::basic_ofstream said:
::~basic_ofstream()'
hw7.cpp:(.text+0x437): undefined reference to
`std::basic_ifstream said:
::~basic_ifstream()'
hw7.cpp:(.text+0x453): undefined reference to
`std::basic_ifstream said:
::~basic_ifstream()'
/tmp/ccN2xrWu.o: In function `bool std::eek:perator><char,
std::char_traits<char>, std::allocator<char> >(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >
const&)':
hw7.cpp:(.text._ZStgtIcSt11char_traitsIcESaIcEEbRKSbIT_T0_T1_ES8_[bool
(std::basic_string<char, std::char_traits<char>, std::allocator<char>
const&, std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&)]+0x19): undefined reference to
::compare(std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&) const'
/tmp/ccN2xrWu.o:(.eh_frame+0x13): undefined reference to
`__gxx_personality_v0'
collect2: ld returned 1 exit status
[cwilson@orion Hw7]$
 
G

Guest

On 05/ 3/12 07:25 PM, Charles Wilson wrote:

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.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;
 
C

Charles Wilson

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.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)


I am not sure if i am understanding you. Forgive me I am a noob. on
all the programs i have created i have used "using namespace std;"
without a problem. How does the namespace effect the string?

in responce to the your question what. That is simply a note for me to
figure exactly how that algorithm is workin.
 
C

Charles Wilson

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.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)


I am not sure if i am understanding you. Forgive me I am a noob. on
all the programs i have created i have used "using namespace std;"
without a problem. How does the namespace effect the string?

in responce to the your question what. That is simply a note for me to
figure exactly how that algorithm is workin.
 
C

Charles Wilson

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.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)


I am not sure if i am understanding you. Forgive me I am a noob. on
all the programs i have created i have used "using namespace std;"
without a problem. How does the namespace effect the string?

in responce to the your question what. That is simply a note for me to
figure exactly how that algorithm is workin.
 
C

Charles Wilson

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.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)


I am not sure if i am understanding you. Forgive me I am a noob. on
all the programs i have created i have used "using namespace std;"
without a problem. How does the namespace effect the string?

in responce to the your question what. That is simply a note for me to
figure exactly how that algorithm is workin.
 
C

Charles Wilson

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.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)


I am not sure if i am understanding you. Forgive me I am a noob. on
all the programs i have created i have used "using namespace std;"
without a problem. How does the namespace effect the string?

in responce to the your question what. That is simply a note for me to
figure exactly how that algorithm is workin.
 
C

Charles Wilson

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.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)


I am not sure if i am understanding you. Forgive me I am a noob. on
all the programs i have created i have used "using namespace std;"
without a problem. How does the namespace effect the string?

in responce to the your question what. That is simply a note for me to
figure exactly how that algorithm is workin.
 
C

Charles Wilson

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.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)


I am not sure if i am understanding you. Forgive me I am a noob. on
all the programs i have created i have used "using namespace std;"
without a problem. How does the namespace effect the string?

in responce to the your question what. That is simply a note for me to
figure exactly how that algorithm is workin.
 
C

Charles Wilson

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.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)


I am not sure if i am understanding you. Forgive me I am a noob. on
all the programs i have created i have used "using namespace std;"
without a problem. How does the namespace effect the string?

in responce to the your question what. That is simply a note for me to
figure exactly how that algorithm is workin.
 
C

Charles Wilson

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.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)


I am not sure if i am understanding you. Forgive me I am a noob. on
all the programs i have created i have used "using namespace std;"
without a problem. How does the namespace effect the string?

in responce to the your question what. That is simply a note for me to
figure exactly how that algorithm is workin.
 
C

Charles Wilson

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.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)


I am not sure if i am understanding you. Forgive me I am a noob. on
all the programs i have created i have used "using namespace std;"
without a problem. How does the namespace effect the string?

in responce to the your question what. That is simply a note for me to
figure exactly how that algorithm is workin.
 
C

Charles Wilson

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.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)


I am not sure if i am understanding you. Forgive me I am a noob. on
all the programs i have created i have used "using namespace std;"
without a problem. How does the namespace effect the string?

in responce to the your question what. That is simply a note for me to
figure exactly how that algorithm is workin.
 
C

Charles Wilson

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.
         {
          maxindex=0;
          for(i=1;i<=end;i++)
                 if(plist.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?
 
C

Charles Wilson

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.
         {
          maxindex=0;
          for(i=1;i<=end;i++)
                 if(plist.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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top