|
From: Maya <Esc...@ne...> - 2004-01-26 03:54:58
|
You know what I would do? I would solve the whole thing by not using the
char array, just use the std::string.
The program is a C++ program, and as a C++ programmer you have to master
the object oriented paradigm. Forger about char, that's a more 'C' kind
of style!
Have good one!!
kpr...@op... wrote:
> Hi Doug,
>
> Thanks for such a thorough response.
>
> Actually, the root of my problem(s) is char vs. string. The problem
> starts right there, because I cannot use string functions on a char
> array. Below, I have gotten to the heart of my lack of
> understanding. That commented-out "string inbufstr" is there because
> up to now, I have been coding that "inbufstr=inbuf" statement to
> convert the char array to a string. Then, I get access to the string
> manipulation functions.
>
> **************************************************************************************
> #include <fstream>
> #include <iostream>
> #include <string>
> using namespace std;
>
> int main(void)
> {
> int i,TotRecs;
> char inbuf[80];
> // string inbufstr;
>
> ifstream MtgRec("Q:\\C++\\AAMtgs.txt");
> ofstream AnalRec("Q:\\C++\\Analysis.txt");
> ofstream ZipRec("Q:\\C++\\Towns.txt");
> if (MtgRec.fail()) {cout << "Cannot open file" << endl;}
>
> i=-1; // 1st iteration is 0 (for 1st subscript)
>
> while (! MtgRec.eof())
> {
> MtgRec.getline(inbuf,80);
> i++;
> TotRecs++;
> }
> // inbufstr=inbuf;
> if (inbuf.substr(0,3) == 'ZIP') inbuf.erase(0,3); // This
> stmt yields error "request for member 'substr' in 'inbuf', which is of
> non-aggregate type 'char[80]'"
> system("pause");
> }
> *************************************************************************************
>
> This is where my flip-flopping around and mixing strings and chars
> begins.
>
> I am sure the answer to this is so simple that I will be astonished
> that I missed it. 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
> list Dev...@li... TO UNSUBSCRIBE:
> http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
--
FYI
http://www.astro.umd.edu/~marshall/abbrev.html
E-Mail Policy
http://www.vif.com/users/escalante/Email_Policy.html
* You cannot exercise your power to a point of humiliation.
- Jean Chretien
* The media's the most powerful entity on earth. They have the
power to make the innocent guilty and to make the guilty
innocent, and that's power.
- Malcom X
* "Innocent until proven guilty", no... not in Canada!!
|