嘿,所以我的代码可以工作,但是我需要正确输出此输出,我需要输出两次输入的字母。它将正确打印一次,但是我添加了一个循环,它将Chars捆在一起,而不是在循环中打印两次。如果我用endl或\ n分开,它将分开字符。我只希望它打印我输入2遍的整行
{
char c;
string s;
int index = 0;
cout << "Enter a line:";
cin.get(c);
while (c != '\n' && index < size) {
x[index] = c;
cin.get(c);
index++;
}
Letter = index;
cout << "" << Letter << endl;
int k = 0;
for (int i = 0; i < Letter; ++i)
{
bool found = false;
for (int j = 0; j < k; ++j)
if (x[i] == x[j])
found = true;
if (!found)
x[k++] = x[i];
s = +x[i];
for (int z = 0; z < 1; z++) {
cout << "" << s;
}
}
Letter = k;
}
答案 0 :(得分:0)
要阅读一行并打印两次:
std::string line;
if (std::cin.getline(line))
{
std::cout << line << '\n' << line << '\n';
}