String Compare problem

1
2
3
4
5
6
fscanf(myScriptFile[WhichScript], "%s", &YO);

			if (YO.compare("Start") == 0)
			{
				Started = true;
			}


for some reason YO.Compare doesnt return 0 at all I have no idea why

im just trying to compare the string (the word start)

the myScriptFile have "Start" in it
What is YO? Is it a std::string?
If so, you can't use it as an argument to fscanf.
Yes, yo is an std::string

it cant?

if i change it to char how would i compare it then?
Last edited on
std::string does not have an implicit conversion to a char * which is what fscanf is expecting in the third parameter. &YO will pass the base address of the string instance which is NOT where the memory is allocated for the data part of the string.

If you're going to use C files and routines, use char and strcmp.
If you're going to use C++, use streams and the >> operator.
1
2
3
4
5
6
  ifstream myfile;
  string YO;

  myfile.open ("filename").
  myfile >> YO;
  if (YO == "Start")


Topic archived. No new replies allowed.