-2

Question has been answered, thanks a lot.

A.j. Schenker
  • 23
  • 1
  • 4

2 Answers2

1

You seem to be confused about how variables work in C++.

Compiling your program with GCC it says:

test.cpp: In function ‘int main()’:
a.cpp:23:20: error: ‘email’ was not declared in this scope
             cin >> email;

That means that there is no such variable named email. You declared a member variable with that name inside your emailverify class, but that will only be used if you define a variable of type emailverify, and you did not do that.

For now, I'd suggest you get rid of the emailverify class and declare the variables you need directly as local variables in main (you could declare them as global, but it is better if you keep them local):

int main()
{
    std::string test;
    std::string email;
    std::string at = "@";
    std::string period = ".";

Then there are a bunch of other errors, such as email.find(at != std::string::npos) instead of email.find(at) != std::string::npos, but you'll get to those eventually.

PS: I know some programming teachers like writing code such as std::string at = "@"; but IMHO that is just silly. Writing email.find("@") is perfectly ok, the extra variable buys you nothing.

rodrigo
  • 86,825
  • 11
  • 134
  • 175
  • Thanks so much! I only tried to use the class because our teacher suggested that we use it. – A.j. Schenker Sep 03 '17 at 21:44
  • @A.j.Schenker: Ah, I fail to see how a class can be useful here. But if you want to try, you have to define a variable of that class `int main() { emailverify e;` and then refer to the member variables as `e.test`, `e.email`, etc. But beware of that local `test` variable you declared, that will be different of `e.test`. – rodrigo Sep 03 '17 at 21:47
0

Your problem is in part of code:

class emailverify
{
public:             // global variables/functions
    std::string test;
    std::string email;
    std::string at = "@";
    std::string period = ".";
};

it does not define global variables or functions but declares class. There is no email or test variable in your main function neither defined or declared.

If you want to stick to globals things you can do is either create global object of type emailverify and use its members via . or make all of them static and access via :: (emailverify::test) or change class into namespace, but it would require defining them outside of class as well (Defining static members in C++).

But, you could just use them as locals and don't worry about all of this right now.

R2RT
  • 1,926
  • 12
  • 24
  • I just tried to do that and dont understand it well enough to be able to implement the global variables. :/ thanks though! – A.j. Schenker Sep 03 '17 at 21:50