From: eyal DOT ben-david AT aks DOT com To: weiqigao AT a DOT crl DOT com cc: djgpp AT delorie DOT com Message-ID: <42256507.00434228.00@aks.com> Date: Wed, 3 Sep 1997 14:23:15 +0200 Subject: Re: Help with strings MID$? Mime-Version: 1.0 Content-type: text/plain; charset=US-ASCII Precedence: bulk Weiqi Gao Wrote: >One way of doing it is to use the GNU C++ class library libgpp.a's >String class. The String class has a member function called at(). Your >BASIC code could be translated to: > >You might also want to check out the third edition of The C++ Language, >which describes the standard C++ library. (I haven't checked, but) I >imagine there would be an ANSI C++ String class that has a member >function that does exactly what the String::at() function does. Here is a sample C++ program that uses the standard C++ string class. The function you are looking for is string::substr(...). it takes two parameters the first is location in the string, the other is the length of the substring that you want to extract. #include #include int main() { string s1 = "Hello DJGPP"; // first parameter is the location, second is LENGTH. // cout << s1.substr(0, 5) << "\n"; // treat 'string::npos' as infinity // int pos = s1.find('D'); cout << s1.substr(pos, string::npos) << "\n"; return 0; }