Thread: ostringstream question

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    30

    Question ostringstream question

    Ok, I've posted about this before but this one is for after I tried something someone suggested about replacing a big ol' case statement with this ostringstream to help reduce the code a lot. It makes sense but the compiler doesn't seem to like it so I guess I'm doing it wrong. I'm trying to make a file name out of an int and a piece of text...a filename that I can actually use (i.e. open and read from). How do I make it use it correctly after I make the filename with ostringstream?

    Stink, I don't have the error messages from the compiler atm but I'll be back to post those soon. Sorry. Thanks for any advice you could throw my way.

    Swaine777


    Code:
    void Hanzi::DisplayRads(int r)
    { 
      ifstream infile;
      
      ostringstream name;
      int i = r;
      name << "rad" << i << ".txt" << flush;
      cout << "\nname is " << name.str() << endl;
      
      string name2 = name.str();
      
      cout << name2 << endl;
      
      infile.open(name2);
      
      if(!infile)
        cout << "Aw, bummer, the file didn't open!\n";
      else
      { char arry[120]; 
        int count = -1;
      
        for(int a=0; a<1; a++)
        { infile.getline(arry[++count], 80, '\n');
        }  
      
        for(int b=0; b<60; b++)
        { if((b=0) || (b%2 == 0))
            cout << b+1 << ". " << arry[b];
          else
            cout << "\t" << b+1 << ". " << arry[b] << endl;
        }        
      }        //if(infile) else
          
      infile.close();
      
    }              //Hanzi::DisplayRads

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    161
    Try:

    infile.open(name2.c_str());

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM