No matching member function for call to 'GetObject' on TFile object

Please read tips for efficient and successful posting and posting code

ROOT Version: 6.19.02
Platform: Windows 10
Compiler: Visual Studio

When I try to run the following code I get the following error. I don’t understand why as when I follow a similar procedure in the console I’m able to call GetObject without any issues on a TFile data type.

void drawspectrum(char *infile)
	TFile *spectrum = new TFile(infile);

	string names[4] = { "c1;1","c1;2","c1;3","c1;4" };

	for (Int_t i = 0; i < 4; i++) {
		TCanvas* readThis = 0;
		spectrum->GetObject(names[i], readThis);
		if (i == 0) {
		else {

Try with

		spectrum->GetObject(names[i].c_str(), readThis);