Solved

Write to text file with columns?

Posted on 2004-10-08
1
148 Views
Last Modified: 2010-04-24
I need to write a program that writes strings and integers to a text file in 2 columns.   I need to be able to append to different columns whenever I need to.  I havnt had to write to a file in awhile so if you could include an example that would be great too. Thanks.
0
Comment
Question by:drumrboy44
1 Comment
 
LVL 19

Accepted Solution

by:
drichards earned 500 total points
ID: 12266083
The basic code to output in columns is something like this:

    std::ofstream outFile;
    outFile.open("<file name>");
    // assume string is in 'std::string txt;' and int is 'int intVal;'
    // this will put the string in a 10 character column and the integer in a 7 character column.
    outFile << std::setw(10) << txt.c_str() << std::setw(7) << int << std::endl;


What do you mean by "append to different columns whenever I need to"?
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question