Please anyone who is familiar with visual C++, please I need your help.
I have this problem in my code that i've been trying to fix without any success.
I have this program that i'm building using Windows Forms. It is about a hospital management system, but I have a problem writing to files. Take an example the following code:
using namespace System;
using namespace System::IO;
int main()
{
FileStream^ fs = gcnew FileStream("data.txt", FileMode::Create);
StreamWriter^ sw = gcnew StreamWriter(fileName);
try{
sw->WriteLine("First Name: ", this->FnameTextBox->Text);
}
catch (Exception^)
{
Console::WriteLine("data could not be written");
fs->Close();
return -1;
}
fs->Close();
return 0;
}
The problem that i'm having is to write both the string and the input from the user (FnameTextBox) to the same line in the text file. This will appear on the text file like this:
First Name: Marlaw19 //if the input was Marlaw19
The code only writes "First Name:" and leaves out the input from the user through the control "FnameTextBox".
I've already declared the text box control and the text box works correctly on it self on its own line eg. sw->WriteLine(this->FnameTextBox->Text);
I've tried every tricks but it is still not working!
Any one who is familiar with Visual C++, Please I need your help.