Menu

using string variabele for filename

Luke
2011-05-17
2012-09-26
  • Luke

    Luke - 2011-05-17

    Wat is wrong with this code? i want to create a file. The name of the file is
    in a string variable.

    include <iostream>

    include <fstream>

    include <string>

    using namespace std;

    int main()
    {
    string naambestand="txt.txt";
    ofstream bestand;
    bestand.open(naambestand);
    bestand.close();
    cout<<naambestand;
    cin.get();
    return 0;
    }

     
  • GReaper

    GReaper - 2011-05-31

    ofstream::open() can't take a string, try: bestand.open(naambestand.c_str());

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.