when i tried to compile it, why i got expected primary-expression before input?

#include "mylibrary.h"
#include "contadd.h" //for function declaration

void Contact::setname(string name)
{
  ofstream myfile;
  myfile.open(CONTACTS);
  if (myfile.is_open());
  {
  myfile<<name<<endl;
  myfile.close();
  }
  
  i++;
}




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(0)<<" added "<<endl;
	string newname = input[i];
	int size = input.size();
	for(int j = 0; j<size; j++)
	{
		if(newname[j] == '@')
			
		{
			cout<<"with email address"<<endl;
			addingname.setname(string input[j]);//error at here*****
			
		
		}
if(newname[j] == '@')
			
		{
			cout<<"with email address"<<endl;
			addingname.setname(string input[j]);//error at here****
			
		
		}

what is meant by expected primary-expression?

Recommended Answers

All 2 Replies

try input.at(j) ... vectors and arrays have differing ways of accessing their members.

I'd also suggest, instead of having:

int size = input.size();	
         for(int j = 0; j<size; j++)

Use this instead:

for(int j = 0; y < (int)input.size(); j++)

It's a pretty minor thing but it'll cut down your creation of unneccessary variables which cannot be a bad thing. :)

alright, thx 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.