-
May 19th, 2006, 05:13 AM
#1
Read filenames from text file ... problem
Hi guys,
The code below does not seam to work properly, even though all the files specified except "image_.png" do exists, the output from the code bellow only show me that the last file exists!
I expect it is something to do with the new line character in windows vs unix
Can anybody help?
Sorry for my ignorance but it has been about 5 years since i did any C++ (been doing nothing but VB since)
Code:
bool SlideshowFile::ParseFile( const char* pName )
{
cout << "SlideshowFile::ParseFile()" << endl;
ifstream inFile;
string line;
int i;
m_ImageList = new string[ 8 ];
inFile.open( pName, ios::in );
if ( ! inFile.is_open() )
{
cout << "Unable to open file";
return false;
}
while( ! inFile.eof() )
{
getline( inFile, line );
if ( ! line.empty() )
{
if ( ! FileExists( line.c_str() ) )
{
cout << "File not found : " << line << endl;
}
else
{
cout << i << " : " << line << endl;
m_ImageList[ i++ ] = line.c_str();
}
}
}
inFile.close();
m_ImageCount = i;
/*
m_ImageList[ 0 ] = "/mnt/smb/nfs/Apps/SDK/jgadd/Album/image.png";
m_ImageList[ 1 ] = "/mnt/smb/nfs/Apps/SDK/jgadd/Album/image1.png";
m_ImageList[ 2 ] = "/mnt/smb/nfs/Apps/SDK/jgadd/Album/image2.png";
m_ImageList[ 3 ] = "/mnt/smb/nfs/Apps/SDK/jgadd/Album/image3.png";
m_ImageList[ 4 ] = "/mnt/smb/nfs/Apps/SDK/jgadd/Album/image_.png";
m_ImageList[ 5 ] = "/mnt/smb/nfs/Apps/SDK/jgadd/Album/image4.png";
m_ImageList[ 6 ] = "/mnt/smb/nfs/Apps/SDK/jgadd/Album/image5.png";
m_ImageList[ 7 ] = "/mnt/smb/nfs/Apps/SDK/jgadd/Album/image6.png";
m_ImageCount = 8;
for ( int i = 0; i < m_ImageCount; ++i )
{
cout << i << " : " << ( const char* )m_ImageList[ i ] << endl;
}
*/
return true;
}
here is the output from the console
Code:
SlideshowFile::ParseFile()
File not found : /mnt/smb/nfs/Apps/SDK/jgadd/Album/image.png
File not found : /mnt/smb/nfs/Apps/SDK/jgadd/Album/image1.png
File not found : /mnt/smb/nfs/Apps/SDK/jgadd/Album/image2.png
File not found : /mnt/smb/nfs/Apps/SDK/jgadd/Album/image3.png
File not found : /mnt/smb/nfs/Apps/SDK/jgadd/Album/image_.png
File not found : /mnt/smb/nfs/Apps/SDK/jgadd/Album/image4.png
File not found : /mnt/smb/nfs/Apps/SDK/jgadd/Album/image5.png
0 : /mnt/smb/nfs/Apps/SDK/jgadd/Album/image6.png
All code on this page is protected by an SEP field!!!
-
May 19th, 2006, 06:39 AM
#2
Re: Read filenames from text file ... problem
>>m_ImageList[ i++ ] = line.c_str();
1. What is the value of i counter before the loop starts? It appears to be uninitiated and hold some random value.
2. If you make m_ImageList a vector of strings then you don't have to allocate some specific value to it, and you don't need that i counter at all.
Code:
vector<string> m_ImageList;
...
...
m_ImageList.push_back(line);
-
May 19th, 2006, 07:10 AM
#3
Re: Read filenames from text file ... problem
I have fixed the problem now,
I would appear that it was related to the difference between unix and windows endofline characters!
All code on this page is protected by an SEP field!!!
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
|