Any Alternate way for writing to a file other than ofstream

I am performing file operations (writeToFile) which fetches the data from a xml and writes into a output file(a1.txt).

I am using MS Visual C++ 2008 and in windows XP.

currently i am using this method of writing to output file..

01.ofstreamhdr OutputFile; 02./* few other stmts */, std::ios::out); 04. 05.hdrOutputFile << "#include \"commondata.h\""<< endl ; 06.hdrOutputFile << "#include \"Commonconfig.h\"" << endl ; 07.hdrOutputFile << "#include \"commontable.h\"" << endl << endl ; 08. hdrOutputFile << "#pragma pack(push,1)" << endl ; 09.hdrOutputFile << "typedef struct \n {" << endl ; 10./* simliar hdrOutputFiles statements... */..

I have around 250 lines to write.. Is any better way to perform this task.

I want to reduce this hdrOutputFile and use a buffer to do this.

Please guide me how to do that action.

I mean,

buff = "#include \"commontable.h\"" + "typedef struct \n {" + ....... hdrOutputFile << buff.

is this way possible?



-------------Problems Reply------------

How about:

const char * buffer =
"This is one line of text\n"
"This is the start of another"
" and this is the end of the same line\n"
"and so on\n";

hdrOutputFile << buffer;

In both C and C++, string literals like this are automatically concatenated into a single string.

Category:visual c++ Views:0 Time:2010-06-18

Related post

  • Age of Mythology Setup encountered a disk error while writing to the file C:\Users\(my name)\Desktop\aom\textures\ 2015-01-27

    Age of Mythology Setup encountered a disk error while writing to the file C:\Users\(my name)\Desktop\aom\textures\ Make sure your hard drive is not full, and that the file is not in use Original title: AOM only installs to 94% When I ins

  • Issue writing to single file in Web service in .NET 2008-09-23

    I have created a webservice in .net 2.0, C#. I need to log some information to a file whenever different methods are called by the web service clients. The problem comes when one user process is writing to a file and another process tries to write to

  • Writing utf16 to file in binary mode 2008-10-16

    I'm trying to write a wstring to file with ofstream in binary mode, but I think I'm doing something wrong. This is what I've tried: ofstream outFile("test.txt", std::ios::out | std::ios::binary); wstring hello = L"hello"; outFile.write((char *) hello

  • Ruby: auto-quote string, not other data, when writing to a file? 2009-09-22

    i'm writing a small library that writes data out to a file. some of the data is strings, some of it is not - things like boolean (true/false) values... when I have a string for data, I want to write the string to the file with quotes around it. so a

  • C++ writing string to file = extra bytes 2009-10-20

    I am using c++ to look through 256 counts and write the ASCII representative to a file. If i use the method of generating a 256 character string then write that string to the file, the file weighs 258bytes. string fileString = ""; //using the counter

  • Writing a CSV file in .net 2009-11-06

    I have a requirement to export a dataset as a CSV file. I have spent a while searching for a set of rules to go by and realised there are quite a few rules and exceptions when writing a CSV file.

  • Writing to a file in as3 flash develop 2010-02-20

    Ive been doing some research and I cant seem to find anything on writing to a file. My initial question was writing a array to a seperate file. But now I am looking for resources on how to write any data such as XML or a array to a file. What I want

  • Writing to a file in Unicode 2010-03-11

    I am having some problems writing to a file in unicode inside my c program. I am trying to write a unicode Japanese string to a file. When I go to check the file though it is empty. If I try a non-unicode string it works just fine. What am I doing wr

  • How to have synchronous writing to a file (Threads)? 2010-03-12

    I created and started some Threads that each one writes something to a common text file. but the following error appears to me: "The process cannot access the file 'C:\hello.txt' because it is being used by another process." void AccessFile() { int n

  • Writing Strings to files in python 2010-03-22

    I'm getting the following error when trying to write a string to a file in pythion: Traceback (most recent call last): File "", line 264, in execute save_off(, context) File "", line 244, in save_off prim

  • how to use "tab space" while writing in text file 2010-04-06

    SimpleDateFormat formatter = new SimpleDateFormat("ddMMyyyy_HHmmSS"); String strCurrDate = formatter.format(new java.util.Date()); String strfileNm = "Cust_Advice_" + strCurrDate + ".txt"; String strFileGenLoc = strFileLocation + "/" + strfileNm; Str

  • EXC_BAD_ACCESS On reading and writing to plist files 2010-07-01

    I'm getting tonnes of EXC_BAD_ACCESS errors related to the following two functions for reading and writing to plist files. I think its memory related. Any suggestions? +(NSString *) getSettingString: (NSString *)key defaultValue:(NSString *)defValue

  • Visual Studio bug - Error writing the project file. Class not registered 2010-07-16

    I have just upgraded from Visual Web Developer Express 2008 to Visual Web Developer Express 2010. However, I can't use it. When I try to create a new project I get a small dialog box that says: Error writing the project file. Class not registered. I

  • Writing to a file on a server with jQuery? 2010-08-16

    I am developing an application which requires the reading and writing of XML files. Reading I've got covered, but is writing possible at all? The layout of my webapp is like this: ../includes/ (irrelevant) ../content.xml (xml to be written to) ../ind

  • Use jpathwatch to find out when a program finished writing to a file 2010-08-30

    I'm currently using jpathwatch to watch for new files created in a folder. All fine, but I need to find out when a program finished writing to a file. The library's author describes on his website ( how that's don

  • Check for writing permissions to file in Windows/Linux 2010-09-26

    I would like to know how to check if I have write permissions to a folder. I'm writing a C++ project and I should print some data to a result.txt file, but I need to know if I have permissions or not. Is the check different between Linux and Windows?

  • How to avoid writing include_once() in file again and again for including different class? 2010-11-18

    I have code structure in which I have class file, template file and controller file. And in every conroller file I have to call atleast 6 include_once(); How to avoid writing include_once() in file again and again for including different class? -----

  • Writing a SQL file from Perl 2010-12-04

    I am a complete newbie to Perl, with PHP coding experience and I put together this Perl script to read a fairly big datafile with no EOL characters and create a SQL file with INSERT statements. My problem is that in the source file there are "special

  • why is bufferedwriter not writing in the file? 2010-12-13

    Here is the code snippet. read = new FileReader("trainfiles/"+filenames[i]); br = new BufferedReader(read); while((lines = br.readLine())!=null){ st = new StringTokenizer(lines); while(st.hasMoreTokens()){ bw = new BufferedWriter(new FileWriter("file

Copyright (C), All Rights Reserved.

processed in 0.164 (s). 11 q(s)