根据每个字符比较同一数组中的两个字符串值.此结果仅显示Last OUT值的原因
compare two string value in same array based on each char . this result only showing Last OUT value why
#include <iostream>
#include <string>
using namespace std;
void Calc( const string, const string , string&);
void Dbf(const string,const string, string&);
int main ()
{
string OUT;
string A[]={"10","12"};
string j = A[0];
string k = A[1];
Calc(j,k,OUT);
cout<< "ODD :"<<j<<endl;
cout<< "EVEN :"<<k<<endl;
cout<< "OUT :"<<OUT<<endl;
cout<< "OUT :"<<OUT<<endl;
// this result only showing Last OUT value why pls help
return 0;
}
void Calc( const string J ,const string K, string& Out){
int OD_L = J.length();
int EV_L = K.length();
int D = (OD_L - 1);
int E = (EV_L - 1);
for(int io = D ; io >= 0; io-- ){
string OD(1, J[io]);
string EV(1, K[io]);
Dbf( OD , EV, Out);
}
}
void Dbf(const string S_odd, const string S_even, string& p_Out){
if(S_odd == S_even){
p_Out = " yes ";
}else{
p_Out = " no " ;
}
}
您似乎正在尝试比较两个字符串,以产生"yes"answers"no"的长结果。在Dbf中,您应该将字符串附加到p_Out,而不是覆盖它。尝试:
void Dbf(const string S_odd, const string S_even, string& p_Out){
if(S_odd == S_even){
p_Out += " yes ";
}
else{
p_Out += " no " ;
}
}
相关文章:
- 尝试将字符串/字符转换为整数会产生意外结果
- 使用 sprintf 和 %g 将双精度转换为字符串的意外结果
- 当我用"ñ"字符循环访问字符串时出现奇怪的结果
- 将字符串强制转换为GUID并不能得到正确的结果
- C++:比较运算符>和字符串文本的意外结果
- 字符串 erase() 函数为类似的调用给出不同的结果
- 提升精神:将结果复制到字符串向量中
- 硬编码字符串与强制转换为 PUCHAR 并打印到控制台时从控制台读取的字符串的结果不同
- 对于字符串中的每个字符都会给出错误的结果
- C++ 字符串的排列,输出的结果小于或等于字符串的长度
- 尝试以随机字符(长读取)打印字符串返回结果
- 访问字符串::c_str()的结果时出现瓦尔格林德内存访问错误
- *char数组到字符串(两次运行代码和两个不同的结果)
- 在尝试提交作业警告时,我一直在警告:与未指定行为的字符串字面结果比较[-WADDRESS]
- 如何使用字符串和整数获取汽车类的整数结果
- 将词法强制转换双倍提升为字符串,给出无效结果
- 如何在字符串中的 时匹配结果
- 我如何在众多字符串中选择一个并显示所有可能的结果
- RapidJSON 在转换为字符串时产生不一致的结果
- 没有得到预期的结果字符串连接