Click here to Skip to main content
15,887,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
CString s=strLine;
int size=s.GetLength();
char* NotesStr;
std::vector<char> notesChar;
int c=0;
for(int n=0;n<size;n++)
{

         while((s[n]!='.')&&s[n]!='T')
	{
		notesChar.push_back(s[n]);
		c++;
		n++;
	}
	if(s[n]=='.')
	{
		std::string NotesStr(notesChar.begin(),notesChar.end());
		for(int p=0;p<c;p++)
		{
			notesChar.pop_back();
						
		}
		c=0;
	}
	else if(s[n]=='T')
	{
		std::string NotesStr(notesChar.begin(),notesChar.end());
		if(NotesStr=='1O')//error comes here
		{
			MessageBox("Hi");
		}
		for(int p=0;p<=c;p++)
		{
			notesChar.pop_back();
						
		}
		c=0;
		break;
	}
}


The above code is giving my the following error
error C2678: binary "==": no operator found which takes a left-hand operand of type std::string(or there is no acceptable conversion)
Posted
Updated 6-Mar-12 23:07pm
v3

what if you change it by:
C++
if(NotesStr=="1O")
 
Share this answer
 
Comments
chaiein 7-Mar-12 6:09am    
no even that cause error but different error
chaiein 7-Mar-12 6:09am    
std::string t="1F";
if(NotesStr.compare(1,t.length(),t))
{
MessageBox("Hi");
}
chaiein 7-Mar-12 6:09am    
The above code works
The reason for the compiler error is that there is no operator for comparing two values of type std::string and char. If your purpose really is to compare two full strings, then you should convert the operand on the right side to std::string as well, as there is in fact a defined operator == for comparing two operands of type std::string.

That said, your right hand side operand uses single hyphens, indicating a single character, not a string. And it isn't even a valid character.

Did you mean a single character with the decimal (or hexadecimal?) value 10? If so, you cannot compare an entire string with a single character, so what was your intention?

Or did you mean the string "10"? If so, the comparison will always be false, as the string you compare to does not contain a 'T', and that is the condition you verified just before. So what did you mean to test?
 
Share this answer
 
Comments
Schehaider_Aymen 7-Mar-12 5:47am    
I don't think that the no use of 'T' will cause an issue, the code below works fine :

<pre lang="c++">
string s2;
s2 ="Test string";

if (s2 == "Test string")
cout << "YES" << endl;

</pre>
Stefan_Lang 8-Mar-12 3:56am    
That thing about 'T' was just a misunderstanding on my part, I thought the preceding if condition was referring to the same string, which it didn't. So that last paragraph of mine is meaningless.
chaiein 7-Mar-12 6:04am    
1O is not ten its one and 'O' Alphabet
Schehaider_Aymen 7-Mar-12 6:09am    
the prob is not 1 and which litteral, if you wanna comapre the string to another and this latter contains just one alphabet so use the ' but if it contains 2 or more alphabets then you ll need the ".
chaiein 8-Mar-12 3:35am    
Thanks for the reply:)
I had to access the data to compare. I got the solution as below
std::string t="1O";
if(NotesStr.compare(1,t.length(),t))
C#
std::string t="1F";
 if(NotesStr.compare(1,t.length(),t))
 {
       MessageBox("Hi");
 }

This works:)
 
Share this answer
 
you can see two variables with same name "NotesStr" in that code block, Try changing the name of std::string NotesStr(notesChar.begin(),notesChar.end());
to some other name.

Also in order to compare string you need to use double quotes instead of single quotes.
string test = "whoami";
if (test == "whoami") printf(...) like that.

jkchan
http://cgmath.blogspot.com
 
Share this answer
 
Comments
chaiein 8-Mar-12 3:35am    
Thanks for the reply:)
I had to access the data to compare. I got the solution as below
std::string t="1O";
if(NotesStr.compare(1,t.length(),t))

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900