|
From: Kenneth P. R. <kpr...@op...> - 2004-01-23 11:03:41
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
<small><font face="Helvetica, Arial, sans-serif">Hi Doug,<br>
<br>
Thanks for such a thorough response.<br>
<br>
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.<br>
<br>
**************************************************************************************<br>
#include <fstream><br>
#include <iostream><br>
#include <string><br>
using namespace std;<br>
<br>
int main(void)<br>
{<br>
int i,TotRecs;<br>
char inbuf[80];<br>
// string inbufstr; <br>
<br>
ifstream MtgRec("Q:\\C++\\AAMtgs.txt");<br>
ofstream AnalRec("Q:\\C++\\Analysis.txt");<br>
ofstream ZipRec("Q:\\C++\\Towns.txt"); <br>
if (MtgRec.fail()) {cout << "Cannot open file" << endl;}<br>
<br>
i=-1; // 1st iteration is 0 (for 1st subscript)<br>
<br>
while (! MtgRec.eof())<br>
{<br>
MtgRec.getline(inbuf,80);<br>
i++;<br>
TotRecs++;<br>
}<br>
// inbufstr=inbuf;<br>
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]'"<br>
system("pause");<br>
}<br>
*************************************************************************************<br>
<br>
This is where my flip-flopping around and mixing strings and chars
begins. <br>
<br>
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.<br>
<br>
TIA,<br>
Ken</font></small><br>
</body>
</html>
|