Вопрос

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

Это было полезно?

Решение

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;

Другие советы

use the getline() methood to get charater and space thats and efficent way.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top