我正在寻找论坛,我仍然找不到我的问题的答案.我有两个字符串,它们只是一个数字数组.例如(我只选择随机数
string input1="12345678909876543212";
string input2="12345";
Run Code Online (Sandbox Code Playgroud)
我想将这两个字符串加在一起,但就像整数一样.我的目标是创建一个类,我可以添加比(long long int)更大的数字,因此它可以超过最大的long long int变量.
所以我没有问题地发现了字符串,现在就在那里
input1="21234567890987654321"
input2="54321"
Run Code Online (Sandbox Code Playgroud)
然后我尝试添加,假设input1 [0] + input2 [0](2 + 5)到一个新字符串让我们称之为newString [0],其中它将等于(7); 但我找不到一个好方法来暂时转换字符串中的当前数字,以便我可以将其添加到新字符串?有谁可以帮忙.我厌倦了atoi,stof,stod.他们似乎根本不适合我.任何方式我都可以使这个功能工作.我不关心上课,我只是想找到一种方法来数学地添加这两个字符串,但仍然保持newString的字符串格式.谢谢你能为我解决这个问题的人
这是我的代码
NSMutableArray * reversedNamesArray; //theres about a thousand variable already stored in here, this is just for documentation
reversedNamesArray = [reversedNamesArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
//Incompatible pointer type assigning "NSMutableArray" to "NSArray"
Run Code Online (Sandbox Code Playgroud)
上面的消息是我得到的,我知道这意味着什么,但我不想采取额外的步骤将一千个变量的NSMutableArray复制到NSArray是否有任何演员我可以用来修复警告,它没有不会影响我的代码,但我只想修复它.你能解释为什么它们不兼容,它们NSMutableArray和NSArray应该使用相同数量的字节,所以我不明白为什么它们首先是不兼容的.
嗨,我无法验证这个字符串是否为全部小数,即使我输入9999它仍然告诉我我的if语句出错.我认为这是一个错字,但我不知道在哪里.
cout<<"Enter a very large number"<<endl;
cin>>In1; //inputs a string
for(int i=0; 0<In1.length();i++){ //the loop that goes thru each index
if (!(isdigit(In1[i]))){ //validates each index
//tells the user to try again
cout<<"You did not enter a valid input, please try again"<<endl;
In1="";
cin>>In1;
i=0;//starts the loop over if reached
}
}
Run Code Online (Sandbox Code Playgroud)
我一直收到"你没有输入有效的输入,请再试一次",无论我输入是对还是错.