我的字符串d
在我的控制台上显示为空(甚至不是空格),这让我感到困惑,因为我将它初始化为“NULL”并且我试图为其分配一个新值,它不是空值。
int main(){
string user_String[99];
int user_Input = 0;
cout << "Please insert up to one hundred Strings: ";
cin >> user_Input;
//Check for range
bool check = false;
while( check == false){
if (user_Input < 1 || user_Input >100){
cout << "Please insert up to one hundred Strings: ";
cin >> user_Input;}
else{
check = true;
break;}
}
//User input
cout <<"Please enter string"<< endl;
for (int counter = 0; counter < user_Input; counter++){
int counter2 = counter + 1;
cout << "Enter String " << counter2 << ": ";
cin >> user_String[counter];
}
//Loopig for most letters
string c = "NULL";
for(int counter = 0; counter < user_Input; counter++){
//Making Sure Coun doesn't go out of range
int coun = 0;
if (counter < user_Input){
coun = counter +1;}
else{
coun = counter;
}
string a = user_String[counter];
string b = user_String[coun];
if (a.length() < b.length() && c == "NULL"){
c = b;
}
if(a.length() < b.length() && c!="NULL" && c.length() < b.length()){
c = b;
}
else{
continue;
}
}
cout << "The string "<< c <<" have the most letters." << endl;
//Looping for least letters
string d = "NULL";
for(int counter = 0; counter < user_Input; counter++){
//Making Sure Coun doesn't go out of range
int coun = 0;
if (counter < user_Input){
coun = counter +1;}
else{
coun = counter;
}
string a = user_String[counter];
string b = user_String[coun];
if (a.length() > b.length() && d == "NULL"){
d = b;
}
if(a.length() > b.length() && d!="NULL" && d.length() > b.length()){
d = b;
}
else{
continue;
}
}
cout << "The string " << d <<" have the least letters." << endl;
system("pause");
return 0;
}