2017-11-06 3 views
0

입력을받는 프로그램을 빌드하고 특정 것을 입력 한 것을 감지합니다. 행을 입력 한 후 으로 소문자로 변환해야합니다. 그러나, 나는 방법을 이해할 수 없다. tolower()를 시도했지만 괄호 안에 무엇을 넣을 지 알 수 없습니다. 코드는 다음과 같습니다.어떻게 문자열을 소문자로 만들 수 있습니까? (C++)

#include <string> 
#include <sstream> 
#include <iostream> 
#include "stdafx.h" 
using namespace std; 
int main() 
{ 
    while (1) 
    { 
     string dir = "C:/"; 
     string line; 
     string afterPrint; 
     string prompt = "| " + dir + " |> "; 
     cout << prompt; 
     cin >> line; 

     stringstream ss(line); 
     while (ss) 
     { 
      string command; 
      ss >> command; 
      command = ;// Command, but lowercase 
      if (command == "cd") 
      { 
       string dir; 
       if (ss >> dir) 
       { 
        cout << "changedir: " << dir << "\n"; 
        string prompt = "| " + dir + " |> "; 
       } 
      } 
      else if (command == "c:" || command == "c:\\" || command == "c:/") 
      { 
       cout << "Directory: " << dir << "\n"; 
      } 
      else 
      { 
       cout << "error\n"; 
      } 
      break; 
     } 
    } 
    return 0; 
} 

도움을 주시면 대단히 감사하겠습니다!

답변

1

tolower은 단일 문자로 작동합니다. 설명서에는 비 알파 문자가 수정되지 않은 채 전달된다는 내용도 나와 있습니다.

이것은 또한 std::transform을 사용하기에 좋은 위치입니다.

std::transform의 예제를 보면 std :: toupper를 사용하여 문자열을 변환하는 예제가 있습니다. 귀하의 필요에 맞게 그 예를 적용하십시오.

관련 문제