By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,376 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

C++ strings to chars to file

P: 1
I am currently trying to figure my way how to output strings to a file.
I have seen all the many posts and such how to do it in a console program, and have had much success doing it that way. This is a gui app though. What I want to be able to do is take strings from a text box, output those strings to char arrays, and then output the char arrays to a text file. Here is what I have so far:

void __fastcall TForm1::Button1Click(TObject *Sender)
class Key //initialize the classes
AnsiString user;
AnsiString host;
AnsiString userid;
AnsiString date;
AnsiString dir;

class Charz
char user;
char host;
char userid;
char date;
char dir;

Key MyKey; //string variables
MyKey.user = User->Text; //get strings from text boxes = Host->Text;
MyKey.userid = UserID->Text; = Date_Time_Box->Text;
MyKey.dir = File_Dir->Text;

Output->Lines->Add(MyKey.user); //output strings to textbox in order that input into file

Output->Lines->Add("User Input Complete");

Charz KeyChar; //char variables

ofstream outputFile("user.gen"); //output file
fstream inputFile;

outputFile << KeyChar.user << "\n"; //char variables to file
outputFile << << "\n";
outputFile << KeyChar.userid << "\n";
outputFile << << "\n";
outputFile << KeyChar.dir << "\n";


Output->Lines->Add("User Settings Written to file");
Output->Lines->Add("Generating Keys....");


It is just a matter of getting the strings in MyKey into the chars in KeyChar.
Sep 30 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.