So I've been working on this project (simple Note Program) to help me learn C++ and provide me with new Features.
Ran into One issue that I am Confuzzled By.
Basically, I have a TextBox and a button. When i Click the Button, what is in the TextBox gets written to a TextFile. But, i get an error message that is really long that ends in..........
"(while trying to match the argument list '(std::ofstream, System::Windows::Forms::TextBox ^))"
I don't familiar with Visual Studio, but it looks like you are trying to pass object to ofstream. There should be something like inpline1.text or something that will return string, contained in inpline1. You should pass that to myfile, not just inpline1.
It does look like you're mixing (native) C++ with C++/CLI, which is a related but different language.
To get the System::String from the TextBox you need to use the Text property
1 2
// assuming inpline1 is a TextBox^
String^ example = inpline1->Text;
and then you need to convert the System::String into something ofstream can understand
1 2 3 4 5 6 7 8 9 10 11
IntPtr hglob = Marshal::StringToHGlobalAnsi(example); // from above
char* data = static_cast<char*>(hglob.ToPointer());
ofstream myfile ("example.txt");
if (myfile.is_open())
{
myfile << data;
myfile.close();
}
Marshal::FreeHGlobal(hglob);
or maybe
1 2 3 4 5 6 7
char buffer[1024]; // need to be careful with buffer size in real code
IntPtr hglob = Marshal::StringToHGlobalAnsi(example);
char* data = static_cast<char*>(hglob.ToPointer());
strcpy(buffer, data);
Marshal::FreeHGlobal(hglob);
// then write contents of buffer out using ofstream
Craps'' ran into another similar issue during the Loading..
So now i Reload that Text File. But im getting another Conversion Error
getting the error Code (C2664)
inp1a is inpline1 From Up Top
1 2 3 4 5 6 7 8 9 10 11 12
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
//cout << line << endl;
inp1a->Text = line; //This is where my issue is, not sure how to Convert this part
}
myfile.close();
}