0

什么都不做,当我调用gets()时它甚至不让我输入,甚至我的IDE都声称“语句无效”。

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int main()
{
char userluv[800], fuusd[800], orig[800], key [51], priv [21];
int tempfussd[800], kint, pint, tint[5], c, lame;

//get the basic info
cout << "key? ";
cin >> key;
cout << "Second key? ";
cin >> priv;
cout << "Your lovely text?:\n";
gets(userluv);

for(c=0; c<=key[c]; c++){
    kint += key[c];
}
for(c=0; c<=priv[c]; c++){
    pint += priv[c];
}

//do stuff to your key
tint[0] = strlen(key) + strlen(priv);
tint[1] = tint[0] * tint[0];

//string to int then do stuff
    for(c=0; c<=userluv[c]; c++){
    tempfussd[c] = userluv[c];
    tempfussd[c] + kint;
    tempfussd[c] * pint;
    tempfussd[c] * tint[1];
}

    cout << "\n" << tempfussd[c] << "\n";

return 0;
}
4

2 回答 2

1

您的 gets() 正在从cin>>priv的最后一个输入中获取 \n 。让它像这样:

cin >> priv;
cout << "Your lovely text?:\n";
cin.get();
gets(userluv);

cin.get(); 将处理\n。立即查看。

于 2012-11-08T04:21:51.790 回答
1

这三行是无效的陈述:

tempfussd[c] + kint;
tempfussd[c] * pint;
tempfussd[c] * tint[1];

您可能省略了and=之后的?+*

上面标识的语句发生在循环中:

for(c=0; c<=userluv[c]; c++){
    tempfussd[c] = userluv[c];
    tempfussd[c] + kint;
    tempfussd[c] * pint;
    tempfussd[c] * tint[1];
}

如果(如评论所暗示的那样)+=and*=是正确的,您可以通过编写来简化事情:

for (c = 0; c <= userluv[c]; c++)
    tempfussd[c] = (userluv[c] + kint) * pint * tint[1];
于 2012-11-08T04:22:12.473 回答