#include <iostream>
using namespace std;
int main()
{
cout << "Do you need to encrypt or decrypt?" << endl;
string message;
getline(cin, message);
int letter2number;
for (int place = 1; place < sizeof(message); place++)
{
letter2number = static_cast<int>(message[place]);
cout << letter2number << endl;
}
}
Run Code Online (Sandbox Code Playgroud)
问题的例子:我输入十五个字母,但只打印四个整数.我输入了七个字母,但只打印了四个整数.
循环仅在我的计算机上出现四次,而不是字符串中的字符数.
这是我遇到的唯一问题,所以如果你看到其他错误,请不要告诉我.(这样更有趣.)
感谢您的时间.
请记住,如果您选择回答问题,我是编程领域的初学者,可能需要比其他人更多解释解决方案如何工作.
谢谢您的帮助.
我的问题是我试图用字符串的一部分进行计算(仅由数字组成),但我不知道如何将单个字符转换为int.该字符串名为"message".
for (int place = 0; place < message.size(); place++)
{
if (secondPlace == 0)
{
cout << (message[place]) * 100 << endl;
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢.