0

Hell ive written some code :

#include <iostream>

#include <string>

using namespace std;

int main()
{
	string a;
	string b;

	a = "ABCDEF";
	b = "$";

	a +=b;

	cout << a;

	if(a.find == 1 , "$")
		cout << "FOUND" << endl;
	else
		cout << "NOTFOUND" << endl;

	if(b.find == 2, "ID")
		cout << "FOUND"<<endl;

return 0;
}

notice the 2nd if is testing b.find which b = "$". Should this not find it?? since for a start "ID" isnt in the string and $ is only 1 char. Can anyone shread any light? And can someone maybe suggest another way of doing this?

Thanks peeps
John :)

3
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by Bench
0
if(a.find == 1 , "$")

Is the syntax correct?

yeh it appears to be does it not?

0

yeh it appears to be does it not?

No, it's very wrong. string::find() is a function.. I very much doubt that line is doing what you expect.

Also, "$" is not a char, it's a const char* - double quotes mean a null-terminated string, wheras '$' is a single char. Although it shouldn't affect the find() function, which takes parameters for both types.

try this instead

if(a.find('$'))
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.