#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <sstream>
#include "tchar.h"
#include "windows.h"
#define COUNTOF(x) ( sizeof(x) / sizeof((x)[0]) )
bool GetCurrentDirectory(TCHAR *obuf, DWORD osize)
{
if ( ! GetModuleFileName(0, obuf, osize) )
{
*obuf = '\0';
return FALSE;
}
TCHAR *lastslash = 0;
for ( ; *obuf; obuf ++)
{
if ( *obuf == '\\' || *obuf == '/' )
lastslash = obuf;
}
if ( lastslash ) *lastslash = '\0';
return TRUE;
}
void main()
{
TCHAR filebuf[256];
char data[100];
std::string tempStr;
std::vector<std::string> output;
if ( GetCurrentDirectory(filebuf, COUNTOF(filebuf)) )
{
wcscat_s(filebuf,_T("\\IrregularShapeSetting.ini"));
TCHAR temp_str[100];
::GetPrivateProfileString(_T("Irregular Shape Setting"), _T("Folder"), _T("="), temp_str, 100, filebuf);
wcstombs(data, temp_str, 100);
std::string ConverToStr = std::string(data);
std::stringstream folders(std::string(data)); // 但問題在這
while (std::getline(folders, tempStr, ',')) // 出錯在這行
output.push_back(tempStr);
for(int i = 0; i < output.size(); i++)
std::cout << output[i].c_str() << std::endl;
}
else
{
wprintf_s(_T("ERROR: cannot get irregular shape inspection setting directory\n"));
}
system("pause");
}