|
-
November 4th, 2009, 03:30 PM
#1
getline problems, need help plz
Hey folks, im having a problem with the getline function, iv looked through all the other threads about getline and the only one that has come close to my problem is: http://www.codeguru.com/forum/showth...hlight=getline
however even their solution isnt working, so figured perhaps its something different.
[ code]
void Grid::GenerateGridTiles(fstream &rMap, POINT ptStartPos)
{
//Initialize the variables required for the loops later
int iLineNum = 0;
int iItemNum = 0;
string sLine, sItem;
m_ptStartPos = ptStartPos;
//Gets the length and height of the entire of the map for saving in the map array.
while(getline(rMap, sLine))
{
istringstream linestream(sLine);
iItemNum = 0;
while(getline(linestream, sItem, ','))
{
iItemNum++;
}
iLineNum++;
}
//Sets up the map array with the appropriate length/width
m_pMap = new Tile*[iLineNum];
for(int i=0; i<iLineNum; i++)
m_pMap[i] = new Tile[iItemNum];
//Assign the tile of the map to the Map Array
iLineNum = iItemNum = 0;
while(getline(rMap, sLine)) <------ this main loop is skipped
{
istringstream linestream(sLine);
iItemNum = 0;
while(getline(linestream, sItem, ','))
{
const char* cItem = sItem.c_str();
int iTileRef = atoi(cItem);
m_pMap[iLineNum][iItemNum] = *_pTiles[iTileRef];
iItemNum++;
}
iLineNum++;
}
//Assign the displayed grid(m_pTileGrid) to a position in the Map
for(int i=0; i<m_iTilesAcross; i++)
for(int j=0; j<m_iTilesDown; j++)
m_pTileGrid[i][j] = m_pMap[(i + m_ptStartPos.x)][(j + m_ptStartPos.y)];
}
[/code]
All the code compiles fine, however the 2nd group of while loops is skipped (marked with <-----)
this presumably is because the condition of the loop are not met, wich leads me to think that after the first set of loops the getline function has encountered the end of file, and hence when the 2nd lot of loops come it skips them.
My question is, is there any way to bring the indicator of what has been 'got' already back to the beginning of the file (rMap is a csv file).
i have already tried:
[ code]
file.seekg(0, ios_base::beg);
file.clear();
[/code]
Any help is appreciated, thanks!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|