2

I know I'm sounding an awful lot like a newb by asking this however I'm curious as to know why I'm getting an error when using simple operators through an if statement on a string? Here is what I am doing to produce the error:

    void Shift (string updown )
{
    if (updown == "hel")
    {
        //random code
    }
}

and my includes would be:

#include <iostream>
#include <fstream>
#include <Windows.h>
using namespace std;
2
  • 2
    what is the error? Also, using namespace is frowned upon. Commented Aug 8, 2012 at 5:22
  • It's not frowned upon (except in .h files and some other cases). using namespace is the best way to make the code manageable and readable. Commented Aug 8, 2012 at 10:32

3 Answers 3

5

Well, you know, try to include the <string> header. And either write std::string or add a using std::string after the include.

Sign up to request clarification or add additional context in comments.

2 Comments

Wow! Thanks! Sorry I can't vote it up I don't yet have 15 rep, but I will when i get it!
@tincopper2 lemme do it for you, +1 :)
1

You forgot

#include <string>

Other header files might include the internal header that provides the std::string class, but without the associated functions such as the == operator you're missing.

1 Comment

Wow! Thanks! Sorry I can't vote it up I don't yet have 15 rep, but I will when i get it!
0

You are attempting to use the std::string class without actually including the necessary header.

Add #include <string> to your list of includes.

1 Comment

Wow! Thanks! Sorry I can't vote it up I don't yet have 15 rep, but I will when i get it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.