On Button click

Status
Not open for further replies.

mleake

Seniorius Lurkius
20
Hi Iam am new too vc++ .net and would like to click a dialog button
and grab the contents of an edit box and put them in a text file.
the edit box name is IDC_Edit1
Here is some example code
void Capp1Dlg::OnBnClickedButton1()
{
ofstream examplefile ("example.txt",ios::app);
if (examplefile.is_open())
{
examplefile <<contents of edit box here

examplefile.close();

}
 

mleake

Seniorius Lurkius
20
okay this is what I got so far

void Capp1Dlg::OnBnClickedButton1()
{
using namespace std;

ofstream examplefile ("example.txt",ios::app);
if (examplefile.is_open())
{
CString cs;
GetDlgItem(IDC_EDIT1)->GetWindowText(cs);
examplefile << cs<<"\n";
examplefile.close();

}

}

When I execute this I type in "hello" and it saves a number to the text file "00336440" why is it saving the number instead of the text?
 

mleake

Seniorius Lurkius
20
I got it to work here is the code

void Capp1Dlg::OnBnClickedButton1()
{
using namespace std;

ofstream examplefile ("example.txt",ios::app);
if (examplefile.is_open())
{
char c[1024]; //variable for contents of edit box
GetDlgItemText(IDC_EDIT1,c,1024); //get contents of edit box
examplefile<<c<<"\n"; //send contents to text file
examplefile.close(); //close text file

}

}
//this saves the text in an edit box to the specified text file
 
Status
Not open for further replies.