?
Solved

Why am I getting this error C++?

Posted on 2009-12-29
4
Medium Priority
?
244 Views
Last Modified: 2013-12-14
I am using this code below.. I used it in another program and it worked fine... but when I copied it to a new program I get an error

int isRunning(string pName)
{
      unsigned long aProcesses[1024], cbNeeded, cProcesses;
      if(!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
            return 3;

      cProcesses = cbNeeded / sizeof(unsigned long);
      for(unsigned int i = 0; i < cProcesses; i++)
      {
            if(aProcesses[i] == 0)
                  continue;

            HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, aProcesses[i]);
            char buffer[50];
            GetModuleBaseName(hProcess, 0, buffer, 50);
            CloseHandle(hProcess);
            string basicstring(buffer);

            if(pName==buffer)
                  return 1;
      }
      return 0;
}


The error I get is
 error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)
1>        could be 'built-in C++ operator==(char [50], char [50])'

The error is for this line
if(pName==buffer)


I can probably easily find a solution to fix it.. but I am curious why I could get the error in 1 program and not the other?
I am using the same compiler, and as far as I can tell all the settings are the same for both projects.
0
Comment
Question by:bail3yz
4 Comments
 
LVL 9

Accepted Solution

by:
magicdlf earned 2000 total points
ID: 26142932
Did you miss #include "string"?
0
 

Author Comment

by:bail3yz
ID: 26142941
Yes yes I did :)
I had #include <string.h>
I added #include <string> and it worked... I didnt know there was a difference

Thanks!
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 26144281
>> I didnt know there was a difference

<string.h> is the C header, and is used for the C library string functions (like strcmp, strcpy, etc.)
<string> is the C++ header, and is used for the std::string class
0
 
LVL 40

Expert Comment

by:evilrix
ID: 26144364
>>  is the C header, and is used for the C library string functions (like strcmp, strcpy, etc.)
You should also note that in C++ this header is deprecated, the correct header to use for the C strings library (if you ever need to use it) is
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question