| | |
Writing text from textbox to file...
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2006
Posts: 9
Reputation:
Solved Threads: 0
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:
and i included
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:
I have to get some kind of way to save the string texts to a varable.. but how..
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:
C++ Syntax (Toggle Plain Text)
file_op<<txt1->Text;
I have to get some kind of way to save the string texts to a varable.. but how..
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
C++ Syntax (Toggle Plain Text)
char text[255]; // or however long the strings are // hWnd is the HWND of the dialog box HWND hEditWnd = GetDlgItem(hWnd,IDC_EDIT1); // get 1st text box GetWindowText(hEditWnd, text);
•
•
Join Date: Jul 2006
Posts: 65
Reputation:
Solved Threads: 14
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:
C++ Syntax (Toggle Plain Text)
System::IO::StreamWriter^ sw = gcnew StreamWriter("file.txt"); sw->WriteLine(txt1->Text);
"What are the roots that clutch, what branches grow
out of this stony rubbish?"
out of this stony rubbish?"
•
•
Join Date: Oct 2006
Posts: 9
Reputation:
Solved Threads: 0
•
•
•
•
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:
C++ Syntax (Toggle Plain Text)
System::IO::StreamWriter^ sw = gcnew StreamWriter("file.txt"); sw->WriteLine(txt1->Text);
•
•
Join Date: Oct 2006
Posts: 9
Reputation:
Solved Threads: 0
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:
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(); )
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(); )
That's because it doesn't go anywhere
Try this:
Try this:
C++ Syntax (Toggle Plain Text)
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { System::IO::StreamReader^ sr=gcnew StreamReader("C:\\Textol.txt"); Txt1->Text = sr->ReadLine(); sr->Close(); }
![]() |
Similar Threads
- Text file formatting by perl (Perl)
- API Help (C++)
- Interactive text file (C++)
- How to send text to a text file using j2me through http connection? (Java)
Other Threads in the C++ Forum
- Previous Thread: Iso Triangle
- Next Thread: C++
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






