Problem with setw

This is a discussion on Problem with setw within the C++ Programming forums, part of the General Programming Boards category; I'm having a problem with setw that I haven't been able to find any information anywhere for. I can't get ...

  1. #1
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728

    Problem with setw

    I'm having a problem with setw that I haven't been able to find any information anywhere for. I can't get setw (or the iosflags like left and right for that matter) to work on strings that are being returned by a function using Dev-C++. Like so:
    Code:
    string func()
    {
      return "Blah";
    }
    
    int main()
    {
       string s="Blah";
    
       cout<<setw(25)<<s<<endl;          // this works
       cout<<setw(25)<<func()<<endl;  // this doesn't work
    
      return 0;
    }
    Anyone know if this is fixable? I had no problems at all using M$ Visual C++ at home...

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Send back a NULL terminate string.

    cout << func().c_str();

    See if that fixes the problem.

    Kuphryn

  3. #3
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Thanks!! That worked perfectly!

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Cool.

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

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