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
{
public:
AnsiString user;
AnsiString host;
AnsiString userid;
AnsiString date;
AnsiString dir;
};

class Charz
{
public:
char user;
char host;
char userid;
char date;
char dir;
};

Key MyKey; //string variables
MyKey.user = User->Text; //get strings from text boxes
MyKey.host = Host->Text;
MyKey.userid = UserID->Text;
MyKey.date = 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(MyKey.host);
Output->Lines->Add(MyKey.userid);
Output->Lines->Add(MyKey.date);
Output->Lines->Add(MyKey.dir);

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


Charz KeyChar; //char variables
KeyChar.user;
KeyChar.host;
KeyChar.userid;
KeyChar.date;
KeyChar.dir;

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

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

outputFile.close();

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.