问题描述
你好,我想做的是花一个月的时间输入(1月2月等)把它变成3个字符串(jan,feb,mar),然后将它们全部改成小写,因此我不会有8个if语句(Jan,JAn,JaN,JAN,jAN,jaN,jAn,jan)来设置(因此需要84个额外的if语句,12个月)
>
我尝试了各种各样的变化,但没有用。(这是我在c ++中的第一堂课,在comp编程中排名第三,所以非常新)
so如果可以的话,请说明相当简单的证据,如果没有任何帮助,我们非常感谢。谢谢。
变量名是包
字符串月;
...(额外变量和狗屎)
getline(cin,month);
...(来自用户的额外输入)
month = month.substr(0, 3);
或者,另一种解决方案是使用像java'的string.equalsIgnoreCase()
ie: if(month.equalsIgnoreCase(" jan"))
{
...
}
什么是sBuffer.begin,我在哪里放入字符串我不想修改,它不是一个char数组,它是一个我正在修改的字符串。拜托,如果你提供帮助,请告诉我它应该如何帮助我,整个讨论会变成一群像女学生一样争论的人。我需要一个示例代码来查看,而不是一个通用的代码,我应该知道那些狗屎意味着什么。比如string.substr(int,int);
被授予,这对于dicipher来说很容易,请说例如:
string s1 =" abc de fgh" ;;
s1 = s1.substr(0,5); //字符串从0开始,而不是1
感谢您的帮助。
hello, what i''m wanting to do is take a month input(january february, etc) turn it to a 3 char string(jan, feb, mar) which i have, and then turn them to all lowercase, so as i don''t haev to have 8 if statements(Jan, JAn, JaN, JAN, jAN, jaN, jAn, jan) to set up(therefore makeing 84 extra ifstatements, 12 months)
I''ve tried all sorts of variations, to no avail.(this is my first class in c++, 3rd in comp programing, so very new)
so please make the explanation fairly dumby proof if you can, if not any help is greatly appreciated. thank you.
the variable name is package
string month;
...(extra variables and shit)
getline(cin, month);
...(extra input from user)
month = month.substr(0, 3);
or, another solution to this would be to use something like java''s string.equalsIgnoreCase()
ie: if(month.equalsIgnoreCase("jan"))
{
...
}
what''s sBuffer.begin, where do i put in the string that i wan''t to modify, its not a char array, its a string that i''m modifying. please, if you offer help, tell me how its supposed to help me, that whole discussion turns into a bunch of ppl arguing like schoolgirls. I need an example code to look at, not a generic one where i''m supposed to know what all that shit means. like string.substr(int, int);
granted, that is an easy one to dicipher, please say for example:
string s1 = "abc de fgh";
s1 = s1.substr(0, 5); //strings start at 0, not 1
thanks for help.
这篇关于C ++字符串为小写方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!