🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gdb.bug
Article #2061

c++ strings with gdb??

#2061
From: Dave
Date: Wed, 15 May 2002 15:21
55 lines
2815 bytes
HI,

All right, I hope I find the right home for my question this time
after I was redirected from one group to another.

I tried my following code :
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main( int argc, char *argv[] ) {

  string linebuffer;
  string substring;
  ifstream inputfile;
  
  inputfile.open(argv[1]);//process them one by one
    
  getline(inputfile,linebuffer);//read in lines  

  substring=linebuffer.substr(0,1);
  
  inputfile.close(); 
  
  return 0;
} // main
after using the -g flag to complie the program with g++, I used gdb to
debug the program. Under gdb, I used "r in", where in the name of the
input file. It contains:
<A HREF="http://www.acm.org/technews/articles/2000-2/0112w.html#item15">The
rush to XML</A>

When I used "p substring" to show the content of "substring", I got :
$10 = {static npos = 4294967295, static nilRep = {len = 0, res = 0,
ref = 1,
    selfish = false}, dat = 0x24340 "<A HREF=\"http:/"}
where the "dat" field is not the expected "<". And also, when I used
"p substring.substr(0,1)" to show the substring of "substring", I got
:
$11 = {static npos = 4294967295, static nilRep = {len = 0, res = 0,
ref = 1,
    selfish = false}, dat = 0x24340 "<A HREF=\"http:/"}
instead of "<" in the dat field. 

Could someone explain what is going on here?

Thanks for clarification.

BTW, why are there so many spam messages in this group, such as
"making money from home" or something like this? And there are also
many un-displayable characters on my screen for many messages. It is
just weird for me. ... Did I find the right group for dicussing gnu
gdb?...
Technical Details
Message-ID: <99f6e996.0205150721.4e1f5157@posting.google.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!212.74.64.35!colt.net!newspeer.clara.net!news.clara.net!news2.euro.net!uunet!ash.uu.net!spool0901.news.uu.net!wendy-fate.uu.net!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f5053,3b612bd1c1e2d578,start
X-Google-Attributes: gidf5053,public
X-Google-ArrivalTime: 2002-05-15 08:21:26 PST
x-uunet-gateway: sjc3sosrv11.alter.net from bug-gdb to gnu.gdb.bug; Wed, 15 May 2002 15:21:22 GMT
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!212.74.64.35!colt.net!newspeer.clara.net!news.clara.net!news2.euro.net!uunet!ash.uu.net!spool0901.news.uu.net!wendy-fate.uu.net!not-for-mail
From: davis_eric@yahoo.com (Dave)
Subject: c++ strings with gdb??
Date: 15 May 2002 08:21:10 -0700
Organization: http://groups.google.com/
Message-ID: <99f6e996.0205150721.4e1f5157@posting.google.com>
NNTP-Posting-Host: 129.97.58.10
Content-Type: text/plain; charset=GB2312
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1021476070 18864 127.0.0.1 (15 May 2002 15:21:10 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: 15 May 2002 15:21:10 GMT
Approved: bug-gdb-request@mail.gnu.org
Newsgroups: gnu.gdb.bug
Sender: bug-gdb-request@mail.gnu.org
Lines: 55