Greetings:
// Get the array length
is.open(".\\hymsel32\\genNum.txt", ios::in);
is>>genlbItems ;
is.close();
I want to read in the size of an array as above.
I need a ( 2-dim ? ) dynamic array whose size may change at run time.
The string obtained from the array must be acceptable by TListbox's
AddString
MAXLBDATALEN is a const; GENCOUNT has to be set at runtime
char GenLBBuf [MAXLBDATALEN] [GENCOUNT]; // = {{ *GenLBBuf[i] }};
is.open(".\\DB\\general.txt", ios::in);
if (genlbItems >= m)
{
for (int r = 0; r < genlbItems; r++)
{
is>>GenLBBuf[r];
GenLBData.AddString(GenLBBuf[r]); // cannot convert int to
const *char
}
}
is.close();
I'm developing this using MS tools as:
if(!inFile.is_open())
{
// inFile.is_open() returns false if the file could not be found or
// if for some other reason the open failed.
cout << "Unable to open file %s\nProgram terminating...\n";
return 0;
}
// File was successfully opened so call the C++ function to read
// all lines from the file.
if (genlbItems >= max)
max = genlbItems; // > array size
// I'm unable to create a 2-dim array acceptable to the compiler.
// This almost works except that nothing (none of the strings in
the file) is in the array
string* temp = new string[max]; // create new larger array.
while(!done) // bool done = false;
{
GetNextLine(inFile, line, strlen(line));
if(strlen(line) == 0)
{
done = true;
inFile.close();
}
for (int i=0; i<max; i++)
{
inFile >> line; //GenLBBuf[i];
temp[i] = line[i];
}
} // end eternal while() loop
delete [] GenLBBuf; // free old array memory.
GenLBBuf = temp; // now it points to new array.
inFile.close(); // Close the data file
cout << "\n\ndone...\n\n";
//--------------------------------------------------------------
// GetNextLine
//
// Purpose: Read a line from a data file.
// Language: C++
// Args: inFile -- istream pointer
// line -- Character array to place the line in.
// lineLen -- Length of the character array line.
// Returns: void
//--------------------------------------------------------------
Thanx, everyone!