我想采取一系列的字符,并将它们分配给一个字符串变量。如何将控制台输出的字符转换为字符串; C++
这里是我的C++代码的摘录,接下来是对问题的进一步描述。
#include <iostream>
#include <string>
using namespace std;
int main() {
string line = "MJQQT BTWQI";
int shift = 5;
int oldShift = 5;
int count = 0;
cout << "Enter your string to shift: ";
getline(cin,line);
cout << "Enter your shift number: ";
cin >> shift;
oldShift = shift;
while(count < line.length())
{
if(line[count] != ' '){
if((line[count]-shift) < 'A')
shift -= 26;
line[count] = line[count] - shift;
shift = oldShift;
cout << line[count];
} else{ line[count] = ' ';
cout << line[count];
}
count++;
}
return 0;
}
输出看起来像:
输入字符串转移:HELLO
输入位移值:5
CZGGJ
我想知道如何分配一次打印出的单个字符这个循环到一个新的字符串。例如,它所需的字符串将是
newString = “CZGGJ”