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;
		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 :)

Recommended Answers

All 3 Replies

if(a.find == 1 , "$")

Is the syntax correct?

if(a.find == 1 , "$")

Is the syntax correct?

yeh it appears to be does it not?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.