I'm trying to search a text file for any email addresses. I'm trying to get it to print the line that every @ sign appears in. However, it is only printing the @ sign instead of the whole line. And I don't understand why.

//gathering emails
  string Emails;
  int i;
  while (getline(fin,Emails))
  {
	  for (i = 0; i < Emails.length(); i++)
	  {
		  if (Emails[i] == '@')
		  {
			  cout << Emails[i] << endl;
		  }
	  }
  }

Change line 10 to cout<<Emails<<endl; , that will print out the whole string.

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.