我正在尝试将输入:“²³”转换为“2,3”,如果不是“²³”则返回“否”
预期结果:
输入密钥:²³ 翻译:2,3,
实际结果:
输入密钥:²³ 翻译:NoNoNoNo
代码:
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
// To Compile: g++ x.cpp -o x
using namespace std;
//Define the functions
string convert( string text);
int main()
{
string d;
string input;
string cleartext;
cout << "Enter the key: ";
cin >> input;
vector <string> key ( input.size() ); // Make a vector with the size of their input
for (int i = 0; i < input.size(); i++) // Fill the vector with the characters given
{
key.at(i)=input[i];
d = convert( key[i]);
cleartext.append(d);
}
cout << "Translated: " << cleartext << endl;
return 0;
}
string convert( string text)
{
if (text == "²")
{
return "2,";
}
if (text == "³")
{
return "3,";
}
return "No";
}
我无法让它正常运行并且很困惑。我猜它必须与逗号有关,任何人都可以添加一些见解吗?