This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

possible bug in string::substr and usablity question


string::substr does not always return
the right substring.

I used the program:
----------------------------------
#include <iostream>
#include <string>
#include <list>

using namespace std;

int main()
{
  string line("testing \"hello\"");

  cout << "  read \"" << line.substr(0,7) << "\"" << endl;
  cout << "  quote read \"" << line.substr(9,11) << "\"" << endl;
  cout << "  constructor \"" << string(line.c_str(), 9, 11) << endl;

  cout << " for loop: ";
  for(int i=9; i<11; i++)
    cout << line.at(i);
  cout << endl;

  return 0;
}
-----------------------------------

and I get
-----------------------------------
 read "testing"
  quote read "hello""
  constructor "hello"
 for loop: he
-----------------------------------

I found and checked out the checklist in my search
for this list. I'm writing an uc layout editor
based on magic. Now I'm wondering if this stl
is ready to be used in that project. Do you
think it's ready? Is it a good way to find
bugs in this stl?

-- Jonathan

-- 
http://www.fastmail.fm - One of many happy users:
  http://www.fastmail.fm/docs/quotes.html


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]