Results 1 to 2 of 2

Thread: Extreme C++ newbie, need help with output string

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    Hi,

    I have about 15 minutes of C++ experience, so excuse my ignorance.

    I have a VB program that needs to output a text string followed by just a line feed and a NULL character. The Print command places a carriage return, line feed and NULL. I was hoping that maybe C++ could help.

    In C++, when I try using "\n", the binary codes at the end of the file are 13 10 0. As far as I can tell that is a carriage return, line feed, and a NULL.

    I need to have just a line feed and a NULL in order for another program to recognize the end of the text string. I can get a 13 0 at the end using "\r", but that does not work.

    My code is:
    Code:
    #include <string>
    #include <fstream>
    #include <iostream>
    using namespace std;
    
    string in_file;
    string out_file;
    
    int main(in_file, out_file) {
    	ofstream outfile( out_file );
    	ifstream infile( in_file );
    
    		if ( ! infile) {
    			cerr << "error: unable to open input file!\n";
    			return -1;
    		}
    
    		if ( ! outfile ) {
    			cerr << "error: unable to open output file!\n";
    			return -2;
    		}
    
    		string word;
    		while( infile >> word)
    			outfile << word << "\r";
    	return 0;
    }
    I have tried every combination of codes I can think of. Is there something else I can try? I have tried outputting "\012" but this places 13 10 0 at the end, just like the Print command in VB is doing.

    Thanks for any suggestions !

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Well if this is all you want to do why don't you do it in VB? It's just as simple.

    You could construct your file from VB in the first place yourself, line by line, and instead of a vbNewLine use a vbLf. Use Put instead of Print.

    Or you could do it with C. I just posted a reply to your other thread, only it's in basic C not C++.
    Harry.

    "From one thing, know ten thousand things."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width