currently I'm building a program which can take people contact and add it to a dat file.
However, when I tried to run the program, i got this

error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript

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();
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"<<" "<<input.at(i)<<" added "<<endl;
for(int j=0;j<input.size();j++)
{
	addingname.setname(input.at[j]); //got error in this section
}

any idea how could this happen? I'm just get started to c++ ..

Recommended Answers

All 2 Replies

Take another look at this: input.at[j].

.at is a function and thus to call a function you need to use the parenthesis, "()" ,
and not the square brakets, "[]".

Also do you really need to use .a()? You aren't even handling if it throws an error.
Just use input[j] instead.

ok i got it. THanks for the help:)

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.