plodata<<

This is a discussion on plodata<< within the C++ Programming forums, part of the General Programming Boards category; I am writing data to a file but want to include an integer (i) in the title of the file. ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    65

    plodata<<

    I am writing data to a file but want to include an integer (i) in the title of the file. How can I go about this?

    i = 0, 1, 2...

    ofstream plotdata("../Data/supersonic_jet(i).vtk", ios:ut);

    filename:

    supersonic_jet0.vtk
    supersonic_jet1.vtk
    supersonic_jet2.vtk
    etc

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Use a stringstream to build the filename.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    65
    can you give me an example please?

  4. #4
    Registered User
    Join Date
    Mar 2007
    Posts
    65
    Say i want to name the file name after string s. How do I go about this?

    string s = "file1.vtk"

    ofstream plotdata("../Data/(s)", iosut);

  5. #5
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    One possible way:
    Code:
    string s = "file1.vtk";
    ofstream plotdata( ("../Data/"+s).c_str() );
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  6. #6
    Registered User
    Join Date
    Mar 2007
    Posts
    65
    Cheers

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21