나는 std
네임 스페이스를 가진 멍청한 사람이다. 나는 디렉토리에있는 모든 jpeg 파일을 반복하고 느낌표를 제거하는 코드를 작성하고있다. std::string
및 std::vector
을 사용하려고합니다. 내 문제는 내 변수 tempname : 말아야 벡터 filelist
변경의 문자열로 const char tempname = (char) *filelist[j].c_str();
변경 (- 여기 내의 WinMain 함수의 고기는 상수 변수 :자동 파일 이름 변경 - const 변수의 값이 변경되고 있습니까?
std::vector<std::string> filelist;
if (!dirExists(directory)) //checks if a directory exists
{
CreateDirectory("resized", NULL);
}
std::vector<std::string> filelist = findFiles("*.jpg"); //finds files in its directory with a given extension
int result; //for rename function
for (unsigned int j=0; j< filelist.size(); j++)
{
std::string::size_type pos = filelist[j].find("!"); //check for exclamation points
if (std::string::npos != pos) //found one at index "pos" in the string
{
switch (MessageBox(window, (LPCSTR)filelist[j].c_str(), "Illegal filename - Rename?", MB_YESNO)) //user input
{
case IDYES:
{
const char tempname = (char) *filelist[j].c_str(); //the problem
//attempt to remove the exclamation point
result = rename(&tempname, filelist[j].erase(pos, 1).c_str());
if (result == 0)
MessageBox(window, "Renamed File", "Information", MB_OK);
else
MessageBox(window, "Error renaming file", "Error", MB_OK);
break;
}
case IDNO:
{
break;
}
}
}
}
파일 이름을 가정. tempname을 const char*
으로 정의했다면 포인터가 될 것이기 때문에 tempname의 값은 변경된 데이터가 변경된 경우 const
선언을 위반하지 않고 바뀔 수 있습니다. 그러나 포인터를 제거하면, 나는 당황 스럽다.
"const를 숯불 tempname는"한 문자입니다 :
은 당신이 아마 원하는 것은 무엇인가이다 – doctorlove