|
From: Per W. <pw...@ia...> - 2004-01-23 11:57:27
|
Since char xx[] is a native type, there are no built-in functions
available for character arrays. If you want to perform any operations, you
must call the global functions declared in string.h.
// Compare first 3 characters in array
if (!strncmp(inbuf,"ZIP",3))
// Locate a substring anywhere in the character array
if (strstr(inbuf,"ZIP"))
/Per W
On Fri, 23 Jan 2004, Kenneth P. Ruppel wrote:
> Hi Doug,
>
> Thanks for such a thorough response.
>
> Actually, the root of my problem(s) is char vs. string.=A0 The problem st=
arts right there, because I cannot use string functions on a char array.=A0
> Below, I have gotten to the heart of my lack of understanding.=A0 That co=
mmented-out "string inbufstr" is there because up to now, I have been
> coding that "inbufstr=3Dinbuf" statement to convert the char array to a s=
tring.=A0 Then, I get access to the string manipulation functions.
>
> *************************************************************************=
*************
> #include <fstream>
> #include <iostream>
> #include <string>
> using namespace std;
>
> int main(void)
> {
> =A0=A0=A0 int i,TotRecs;
> =A0=A0=A0 char inbuf[80];
> // =A0=A0 string inbufstr;=A0=A0
> =A0=A0=A0
> =A0=A0=A0 ifstream MtgRec("Q:\\C++\\AAMtgs.txt");
> =A0=A0=A0 ofstream AnalRec("Q:\\C++\\Analysis.txt");
> =A0=A0=A0 ofstream ZipRec("Q:\\C++\\Towns.txt");=A0=A0=A0
> =A0=A0=A0 if (MtgRec.fail()) {cout << "Cannot open file" << endl;}
>
> =A0=A0=A0 i=3D-1;=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 // 1st iteration is 0 =
(for 1st subscript)
>
> =A0=A0=A0 while (! MtgRec.eof())
> =A0=A0=A0 {
> =A0=A0=A0 MtgRec.getline(inbuf,80);
> =A0=A0=A0 i++;
> =A0=A0=A0 TotRecs++;
> =A0=A0=A0 }
> // =A0=A0 inbufstr=3Dinbuf;
> =A0=A0=A0 if (inbuf.substr(0,3) =3D=3D 'ZIP')=A0 inbuf.erase(0,3);=A0=A0 =
=A0=A0 // This stmt yields error "request for member 'substr' in 'inbuf', w=
hich is of
> non-aggregate type 'char[80]'"
> system("pause");
> =A0=A0=A0 }
> *************************************************************************=
************
>
> This is where my flip-flopping around and mixing strings and chars begins=
=2E=A0
>
> I am sure the answer to this is so simple that I will be astonished that =
I missed it.=A0 But I'm a real quick study, so go ahead, tell me the way
> out of this.
>
> TIA,
> Ken
> ------------------------------------------------------- The SF.Net email =
is sponsored by EclipseCon 2004 Premiere Conference on Open Tools
> Development and Integration See the breadth of Eclipse activity. February=
3-5 in Anaheim, CA. http://www.eclipsecon.org/osdn
> _______________________________________________ Dev-cpp-users mailing lis=
t Dev...@li... TO UNSUBSCRIBE:
> http://www23.brinkster.com/noicys/devcpp/ub.htm https://lists.sourceforge=
=2Enet/lists/listinfo/dev-cpp-users
>
|