string Q

This is a discussion on string Q within the C++ Programming forums, part of the General Programming Boards category; I have a recurring code section that writes data files to a specific directory. ../../Data_x_r/PR2/Scheme_2_TVD_1/. Can i specify as a ...

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

    string Q

    I have a recurring code section that writes data files to a specific directory.
    ../../Data_x_r/PR2/Scheme_2_TVD_1/. Can i specify as a string "'constant" so that I only change it once rather going through every instance and changing it. Hope I am clear

    Code:
        stringstream ss;
        string file_name;
    
        ss << "surface_z_" << Hori_L/Diameter << "D_PR_" << P_r << "Pe_Ma_" << Mach << "_Time_" << timer1 << ".dat";
        file_name = ss.str();
    
       
        ofstream plotdata(("../../Data_x_r/PR2/Scheme_2_TVD_1/"+file_name).c_str());
    Shuo

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    Code:
      const string outfile = "../../Data_x_r/PR2/Scheme_2_TVD_1/";
    Edit: outfile is a bad name, outdir would be better.
    Last edited by robatino; 02-22-2008 at 08:05 PM.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    Code:
    string file_path = "../../Data_x_r/PR2/Scheme_2_TVD_1/"+file_name;
    ?

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,762
    But to answer your question maybe:

    I'm not sure that a constant string is completely appropriate, expecially if you have to loop these statements repeatedly. I know that open()'s fist argument is passed as a constant, so you probably have nothing to worry about (in terms of the data changing) in this context.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compare structures
    By lazyme in forum C++ Programming
    Replies: 15
    Last Post: 05-28-2009, 03:40 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 05:30 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM

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