Writing text from textbox to file...

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2006
Posts: 9
Reputation: DmD is an unknown quantity at this point 
Solved Threads: 0
DmD DmD is offline Offline
Newbie Poster

Writing text from textbox to file...

 
0
  #1
Oct 9th, 2006
So I'm working on a program where you fill in some textboxes and press a button to generate a .txt file with the texts in it...

I'm working in Visual Studio Express (C++)

The only thing i have so far is:
private: System::Void btnAdd_Click(System::Object^ sender, System::EventArgs^ e)
{
char text1[20]
 
fstream file_op("C:\\Textol.txt", ios::out); 
file_op<<text1;
file_op.close();

and i included
#include<fstream>
#include<conio.h>
#include<stdio.h>
 
// and added to namespaces 
 
usingnamespace std;

The textboxes are auto generated etc...

The problem is How to I write the text from the textboxes into my file.. i cant add them like this:

  1.  
  2. file_op<<txt1->Text;


I have to get some kind of way to save the string texts to a varable.. but how..
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1461
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: Writing text from textbox to file...

 
0
  #2
Oct 9th, 2006
You know the ID of each text box, right? And you have the HWND of the dialog box that contains the edit controls, right? Then use GetWindowText() for each box
  1. char text[255]; // or however long the strings are
  2. // hWnd is the HWND of the dialog box
  3. HWND hEditWnd = GetDlgItem(hWnd,IDC_EDIT1);
  4. // get 1st text box
  5. GetWindowText(hEditWnd, text);
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 65
Reputation: GloriousEremite will become famous soon enough GloriousEremite will become famous soon enough 
Solved Threads: 14
GloriousEremite GloriousEremite is offline Offline
Junior Poster in Training

Re: Writing text from textbox to file...

 
0
  #3
Oct 9th, 2006
Since it appears you are using managed (.NET) code, why not use the .NET classes for file IO? I'm no expert at C++/CLI but it might be as simple as:
  1. System::IO::StreamWriter^ sw = gcnew StreamWriter("file.txt");
  2. sw->WriteLine(txt1->Text);
"What are the roots that clutch, what branches grow
out of this stony rubbish?"
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 9
Reputation: DmD is an unknown quantity at this point 
Solved Threads: 0
DmD DmD is offline Offline
Newbie Poster

Re: Writing text from textbox to file...

 
0
  #4
Oct 10th, 2006
Originally Posted by GloriousEremite View Post
Since it appears you are using managed (.NET) code, why not use the .NET classes for file IO? I'm no expert at C++/CLI but it might be as simple as:
  1. System::IO::StreamWriter^ sw = gcnew StreamWriter("file.txt");
  2. sw->WriteLine(txt1->Text);
Thanks allot that really helped :cheesy: :cheesy:
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 9
Reputation: DmD is an unknown quantity at this point 
Solved Threads: 0
DmD DmD is offline Offline
Newbie Poster

Re: Writing text from textbox to file...

 
0
  #5
Oct 10th, 2006
OK so thanks for your help, onto the next problem!! :cheesy:

now that i wrote the text to the .txt file I want it (when the form loads) to read the text and display it in the textboxes....

what i got is this:
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
System::IO::StreamReader^ sr=gcnew StreamReader("C:\\Textol.txt");
sr->ReadLine();
sr->Close();
}

I'm jsut asking myself do I transfer the text in one action, or do i have to save it to a variable... (I don't have any idea where the text goes when I use sr->Readline(); )
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,826
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 297
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Roasting Maven

Re: Writing text from textbox to file...

 
0
  #6
Oct 10th, 2006
That's because it doesn't go anywhere
Try this:


  1. private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
  2. {
  3. System::IO::StreamReader^ sr=gcnew StreamReader("C:\\Textol.txt");
  4. Txt1->Text = sr->ReadLine();
  5. sr->Close();
  6. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 9
Reputation: DmD is an unknown quantity at this point 
Solved Threads: 0
DmD DmD is offline Offline
Newbie Poster

Re: Writing text from textbox to file...

 
0
  #7
Oct 12th, 2006
Thanks again that really helped, i guess im not that good yet at logical thinking *YET*
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,826
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 297
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Roasting Maven

Re: Writing text from textbox to file...

 
0
  #8
Oct 12th, 2006
Practice makes perfect ;-)

gr Niek
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC