Reputation: 154
int main()
{
string path = "c:\\encryption\\";
string searchPattern = "*.txt";
string fullSearchPath = path + searchPattern;
WIN32_FIND_DATA FindData;
HANDLE hFind;
hFind = FindFirstFile( fullSearchPath.c_str(), &FindData );
if( hFind == INVALID_HANDLE_VALUE )
{
cout << " !!! Error searching directory !!!" << endl;;
return -1;
}
do
{
string filePath = path + FindData.cFileName;
ifstream in( filePath.c_str() );
if( in )
{
//////////////////////// HERE IS PROBLEM I KNOW THAT BUT WHAT I DON'T KNOW
char s;
while (!in.eof())
{
in >> s;
cout << s << endl;
}
cout << "************************ File Completely Read *** **************************** " << endl;
///////////////////////////////////////////////////////////////////////
}
else
{
cout << " !!! Problem opening file !!!" << FindData.cFileName << "\n";
}
}
while( FindNextFile(hFind, &FindData) > 0 );
if( GetLastError() != ERROR_NO_MORE_FILES )
{
cout << " !!! Something went wrong during searching !!! " << endl;
}
return 0;
}
I am reading all the files from a specific folder one by one And then for each file reading it character by character.. Above is my effort so far Now, I am stuck in a part that i want to read white spaces as well.. What should i do ? what should i include? Kindly give me some suggestions
Upvotes: 0
Views: 1080
Reputation: 35
use the getline() methood to get charater and space thats and efficent way.
Upvotes: 1
Reputation: 4012
The >>
and <<
operators are designed for formatted operations, while you need binary operations. Try opening the stream with ios::binary
:
ifstream in( filePath.c_str(), ios::binary );
and using read
(or readsome
) and write
to handle I/O.
If you want to stick with formatted operations (which you shouldn't if you`re into encryption), use getline
to read lines containing whitespace characters;
Upvotes: 3