CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2008
    Posts
    10

    Outputting to a file question

    I have the piece of code:

    outfile.open (filename.c_str());

    where filename is the filename.txt provided by the user.

    However, how would I add .csv to end of that so I can change the file extension and create a new file?

    so basically the outfile name would look like this

    filename.txt.csv

    -jeff

  2. #2
    Join Date
    Jun 2006
    Location
    M31
    Posts
    885

    Re: Outputting to a file question

    There are quite a few ways of doing this.
    Assuming that filename contains expected data, this is one option:
    Code:
    outfile.open(std::string(filename + ".csv").c_str());

  3. #3
    Join Date
    Oct 2004
    Posts
    296

    Re: Outputting to a file question

    Code:
    	string str;
    	str = "hello";
    	str += " world";
    	cout<<str<<endl;  //hello world

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

Featured