When i tried to compile it, it gave me this error "no match for operator". Any idea how could this happen? This program will take user input and add it into dat file

#define CONTACTS "contacts.dat"
#include <iostream> //enable the used of cin and cout 
#include <fstream>  //enable writing file and reading file, ofsream and ifstream
#include <cstdlib> //enable for exit() function
#include <vector>  //enable function of vector array 
#include <ctype.h>


using namespace std;

class Contact{
	private: 
	int phones;
	string email;
	string name;
	
	public:
	void setname(string name);
	string takename();
	void setphone(int numbers);
	int takephone();
	void setemail(string mail);
	string takeemail();
	
};

int i =0;
void Contact::setname(string name)
{
  ofstream myfile;
  myfile.open(CONTACTS);
  if (myfile.is_open());
  {
  myfile<<name<<endl;
  myfile.close();
  }
  
  
}
int main(int argc, char* argv[])
{
	vector <string> input;
	Contact addingname;
	
if (argc == 2)
{
	input.push_back(argv[1]);
	cout<<"Ok, contact "<<" "<<i+1<<input.at(i)<<" added "<<endl;
	
	int size = input.size();
	for(int j = 0; j<size; j++)
	{
		if(input[i] == '@') //error in this section, no match for operator?
			
		{
			cout<<"with email address"<<endl;
		
		}
		else
			{
			i++;
			}
		
	}
	
}

	for(int j=0;j<int(input.size());j++)
	{
	
		addingname.setname(input.at(j));
		input.erase(input.begin(),j); //and error in this section as well?a long error
	}
}

You haven't given a specific Line number for us to look at, but I'm guessing the error points to a line where you use an std::string.

You have not included the standard header <string> all of the functions and operators related to the std::string class are defined in that header. Without it, you can't do much with one.

int size = input.size();
#
for(int j = 0; j<size; j++)
#
{
#
if(input[i] == '@') //error in this section, no match for operator?
#

I meant for this if section, why it will give me "no match for operator" any idea?

Do this instead :

if(input[i] == "@") //notice the double quotes
{
 //...
}

yup that solve my problem, and i got another error

for(int j=0;j<int(input.size());j++)
	{
	
		addingname.setname(input.at(j));
		input.erase(input.begin(),j);//error in here

it gave me an error 'no matching for function call std::........' need help again..

If you are trying to erase all contents from the beginning of input until the index
j, then do this:

input.erase(input.begin(), input.begin() + j)

cool, thanks for the help again:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.