0

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

2
Contributors
2
Replies
5
Views
7 Years
Discussion Span
Last Post by Bigbrain99
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.