windows form, 2 issues. getline no instance of overloaded function

as the title says, im using ifstream to read from a file(its a single line of text). then im using getline to store it and print it out, however i cant seem to get it to compile, ive spent a few hours trying to resolve this error, ive fixed them all except for these two which im lost with. also im trying to have the user enter their windows username to find the appdata path to a file ive put in my game's folder called testtext.txt. its putting a redline under "C:/Users/"

1
2
3
4
5
6
7
8
9
10
11
12
13
 
String^ readme;
		ifstream readmeFile("C:/Users/" + textBox_Username->Text + "/AppData/Local/MX Simulator/testtext.txt");

		if (readmeFile.is_open())
		{
			getline(readmeFile, readme);
			readmeFile.close();
		}
		else
		{
			//messagebox cant find file
		}
Last edited on
try this form:

readmefile.getline(stringvar, intmax2read)

and post the actual error messages you get after this change & a compile
throws these. the red line moved from getline to the .
1
2
3
4
Severity	Code	Description	Project	File	Line	Suppression State
Error (active)		no instance of overloaded function "std::basic_ifstream<_Elem, _Traits>::getline [with _Elem=char, _Traits=std::char_traits<char>]" matches the argument list	windowsformtest	c:\Users\Cody\Documents\Visual Studio 2015\Projects\windowsformtest\windowsformtest\MyForm.h	120	
Error	C2664	'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::getline(_Elem *,std::streamsize,_Elem)': cannot convert argument 1 from 'System::String ^' to 'char *'	windowsformtest	c:\users\cody\documents\visual studio 2015\projects\windowsformtest\windowsformtest\MyForm.h	120	


1
2
3
4
5
6
7
8
9
10
11
12
13
14
String^ readme;


		ifstream readmeFile("C:/Users/Cody/AppData/Local/MX Simulator/readme.txt");

		if (readmeFile.is_open())
		{
			readmeFile.getline(readme, '20');
			readmeFile.close();
		}
		else
		{
			system("pause");
		}
Last edited on
//Solved. had something related to what type of string it was and cause the error for getline.
Topic archived. No new replies allowed.