gpt4 book ai didi

c++ - 如何使字符串小写(最简单的方法)? (C++)

转载 作者:行者123 更新时间:2023-11-28 04:55:58 25 4
gpt4 key购买 nike

<分区>

我正在构建一个接受输入的程序,然后检测是否输入了特定内容。输入该行后,应该将其转换为小写。但是,我无法弄清楚如何。我试过 tolower(),但我不知道要在括号中放什么。这是代码:

#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;
}

非常感谢您的帮助!

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com