CODE works in DEV but not in VISUAL STUDIO..need coding advice

Please help me figure out what code changes i need to apply!!
I need this done asap so please help!



#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int a1;
int a2;
int a3;
int a4;

int n;


int choice;
string filename;


struct contact //THE INFAMOUS STRUCT.
{ string lastName;
string firstName;
string homePhone;
string cellPhone;
string officePhone;
string pager;
string faxNumber;
};


ifstream inFile; //USED FOR OPENING FILE
int i; //THE COUNTER.
contact List[200]; //ARRAY TO BE STORED IN.
string searchname; //USED WHEN SEARCHING FOR NAME
string searchnum; //USED WHEN SEARCHING FOR NUMBER.


cout<<"Please enter the name of your file below:"<<endl; ////////////////////////////////////
cout<<endl;
cin>>filename; ////// ///
inFile.open(filename.c_str()); ///// GATHERING ////
if (!inFile) //// OF /////
{cout<<"your file did not open";} // INFO //////
if (inFile)
{
cout<<endl<<"How many contacts do you have in your file?"<<endl<<endl; //used for counter of loop storing struct arrays.
cin>>n;



cout<<endl<<"how would you like to search for your contacts?"<<endl<<"if by name press 0,"<<endl<<"or press any other number to search by Home Phone number:"<<endl<<endl;

cin>>choice;

if (choice==0) /////////////////////////////////////////////////
{ // //
// IF CHOSEN TO SEARCH BY NAME //
i=0; // //
// //
/////////////////////////////////////////////////
while(i<n) // //
{ // //
inFile >> List[i].lastName; // //
inFile >> List[i].firstName; // STORING OF THE INFO //
inFile >> List[i].homePhone; // FROM THE FILE //
inFile >> List[i].cellPhone; // //
inFile >> List[i].officePhone; // //
inFile >> List[i].pager; // //
inFile >> List[i].faxNumber; // //
// //
i=i+1; // //
// //
// //
} /////////////////////////////////////////////////
i=0;
cout<<endl<<"enter The last name of the contact you are trying to reach"<<endl<<endl;

cin>>searchname;
i=0;
while (searchname!=List[i].lastName)
{i++;}

//----------------------------IF SEARCHED BY NAME----DISPLAY-----------------------------//
cout<<endl;
cout<<List[i].lastName<<" , "<<List[i].firstName<<endl;
cout<<"--------------------"<<endl;
cout<<"Home Phone: "<<List[i].homePhone<<endl;
cout<<"Office Phone: "<<List[i].officePhone<<endl;
cout<<"Cell Phone: "<<List[i].cellPhone<<endl;
cout<<"Pager: "<<List[i].pager<<endl;
cout<<"Fax Number: "<<List[i].faxNumber<<endl;
cout<<endl;
}


//--------------------------SEARCH BY PHONE NUMBER--------------------------//
//--------------------------------------------------------------------------//
//--------------------------------------------------------------------------//
else
{

i=0;
while(i<n)
{
inFile >> List[i].lastName; // IF CHOSEN FOR SEARCHING NUMBERS
inFile >> List[i].firstName;
inFile >> List[i].homePhone;
inFile >> List[i].cellPhone;
inFile >> List[i].officePhone;
inFile >> List[i].pager;
inFile >> List[i].faxNumber;

i=i+1;


}
i=0;
cout<<"enter the Home Phone number of the contact you want:"<<endl<<endl;

cin>>searchnum;
i=0;
while (searchnum!=List[i].homePhone)
{i++;}
//----------------------------------------------------------------------------
//-----------------------Display of selected contact------------------------
//----------------------------------------------------------------------------
cout<<endl;
cout<<List[i].lastName<<" , "<<List[i].firstName<<endl;
cout<<"--------------------"<<endl;
cout<<"Home Phone: "<<List[i].homePhone<<endl;
cout<<"Cell Phone: "<<List[i].cellPhone<<endl;
cout<<"Office Phone: "<<List[i].officePhone<<endl;
cout<<"Pager: "<<List[i].pager<<endl;
cout<<"Fax Number: "<<List[i].faxNumber<<endl;
cout<<endl;
}
}
system ("pause");
}

http://www.catb.org/~esr/faqs/smart-questions.html#beprecise
http://www.catb.org/~esr/faqs/smart-questions.html#code


what does "it doesn't work" mean?

Do you get compiler errors? If so tell us what they are.

Does it compile but doesn't behave as expected? If so explain desired behavior and the behavior you're actually getting.

Does it crash? If so describe exactly what happens, how far in the program you get, and to the best of your understanding what is making it crash (when you provide certain input -- or always just after startup).

Just saying "this doesn't work" and pasting a huge chunk of code (which isn't even in [code] [/code] tags) makes us have to do a lot of unnecessary work to try and help you. I for one tend to not bother with posts like these (no matter how urgently you claim to need the info) but felt like chiming in with a post like this because I've been seeing a lot of these kinds of posts here lately.
Last edited on
I have been getting this error on the compiler and the same error comes up ten times for my "cins"

error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

Im sorry for the lack of info and im grateful you are trying to help :)
I searched the whole source and I didn't see you use << with 'cin' anywhere, so I'm guessing you're misinterpretting the error.

please edit your original post and put the code in code tags:

[code]
.. put your code here ..
[/code]

Then please tell me what line(s) the errors are occuring on.

PS - just tried compiling in GCC and it works fine (I'm guessing 'DEV' also uses GCC -- which is why it works there as well). I don't have MSVS to test with, so unfortunately I can't see the errors for myself.
Last edited on
try to #include <string>


error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)

I get this error on line 40, 63, 64 , 65, 66, 67,68,69


and then I get this on line 80
rror C2677: binary '!=' : no global operator defined which takes type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversi
on)



#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int a1;
int a2;
int a3;
int a4;

int n;


int choice;
string filename;


struct contact
{ string lastName;
string firstName;
string homePhone;
string cellPhone;
string officePhone;
string pager;
string faxNumber;
};


ifstream inFile;
int i;
contact List[200];
bool searchname;
string searchnum;


cout<<"Please enter the name of your file below (including .txt, .RTF....etc)"<<endl;
////////////////////////////////////
cout<<endl;
cin>>filename;
inFile.open(filename.c_str());
if (!inFile)
{cout<<"your file did not open"<<endl<<endl;}
if (inFile)
{
cout<<endl<<"How many contacts do you have in your file?"<<endl<<endl; //used for counter of loop storing struct arrays.
cin>>n;



cout<<endl<<"how would you like to search for your contacts?"<<endl<<"if by name press 0,"<<endl<<"or press any other number to search by Home Phone number:"<<endl<<endl;

cin>>choice;

if (choice==0)
{

i=0;


while(i<n)
{
inFile >> List[i].lastName;
inFile >> List[i].firstName;
inFile >> List[i].homePhone;
inFile >> List[i].cellPhone;
inFile >> List[i].officePhone;
inFile >> List[i].pager;
inFile >> List[i].faxNumber;

i=i+1;


}
cout<<endl<<"enter The last name of the contact you are trying to reach"<<endl<<endl;

cin>>searchname;
i=0;
while (searchname!=List[i].lastName)
{i++;}


cout<<endl;
cout<<List[i].lastName<<" , "<<List[i].firstName<<endl;
cout<<"--------------------"<<endl;
cout<<"Home Phone: "<<List[i].homePhone<<endl;
cout<<"Office Phone: "<<List[i].officePhone<<endl;
cout<<"Cell Phone: "<<List[i].cellPhone<<endl;
cout<<"Pager: "<<List[i].pager<<endl;
cout<<"Fax Number: "<<List[i].faxNumber<<endl;
cout<<endl;
}



else
{

i=0;
while(i<n)
{
inFile >> List[i].lastName;
inFile >> List[i].firstName;
inFile >> List[i].homePhone;
inFile >> List[i].cellPhone;
inFile >> List[i].officePhone;
inFile >> List[i].pager;
inFile >> List[i].faxNumber;

i=i+1;


}
i=0;
cout<<"enter the Home Phone number of the contact you want:"<<endl<<endl;

cin>>searchnum;
i=0;
while (searchnum!=List[i].homePhone)
{i++;}

cout<<endl;
cout<<List[i].lastName<<" , "<<List[i].firstName<<endl;
cout<<"--------------------"<<endl;
cout<<"Home Phone: "<<List[i].homePhone<<endl;
cout<<"Cell Phone: "<<List[i].cellPhone<<endl;
cout<<"Office Phone: "<<List[i].officePhone<<endl;
cout<<"Pager: "<<List[i].pager<<endl;
cout<<"Fax Number: "<<List[i].faxNumber<<endl;
cout<<endl;
}
}
system ("pause");
}
hey bazzy thanks, now i only have two errors


H:\Private\My Documents\PROJECT 5 COMPLETE.cpp(80) : error C2677: binary '!=' : no global operator defined which takes type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversi
on)


H:\Private\My Documents\PROJECT 5 COMPLETE.cpp(80) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.



Someone please help :)
in while (searchname!=List[i].lastName); you are comparing a string with a bool
Topic archived. No new replies allowed.