0

I have a program which needs to take the logical drives returned from the GetLogicalDriveString function and store them in a string array for later use in a filepath. I tried doing this directly and it failed. Here's my code:

#include "stdafx.h"
#include <iostream>
#include <io.h>
#include <time.h>
#include <string>
#include <windows.h>
#include <direct.h>
#include <stdio.h>
#include <tchar.h>
#include <Lmcons.h>
#include <sstream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
CHAR name [ UNLEN + 1 ];
  DWORD size = UNLEN + 1;

  if (GetUserName( (CHAR*)name, &size ))
    wcout << L"Hello, " << name << L"!\n";
  else
    cout << "Hello, unnamed person!\n";

	TCHAR szBuffer[1024];
::GetLogicalDriveStrings(1024, szBuffer);
TCHAR *pch = szBuffer;
while (*pch) {
_tprintf(TEXT("%s\n"), pch);
pch = &pch[_tcslen(pch) + 1];
}
   int arraylength = sizeof( pch );
   cout << arraylength << endl;
   string drive[1025];

int i;
i = 0;

if (i < arraylength)
{
	i++;
	drive[i] = pch[i];
	cout << drive[i] << endl;
}
	return 0;
}
2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by MosaicFuneral
0

Like a for() loop, because it just boils down to drive[1] = pch[1]; Mentioned in your CodeGuru thread, mixing wides with ASCII can lead you into problems from messy code.

Edited by MosaicFuneral: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.