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++;}
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.
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.
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;
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;
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.