0

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?

Edited by Bigbrain99: n/a

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

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. :)

This topic has been dead for over six months. 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.