我不明白为什么这在 Visual Studio 2012 中无法正常运行
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
char nullChar()
{
char ch;
int ran = (rand() % 52);
if (ran < 26)
{
ch = (char) ('a'+ ran);
}
else
{
ch = (char) ('A'+ ran - 26);
}
return ch;
}
int main(int argc, char *argv[])
{
cout << "Enter a string";
int nullNum = 0;
nullNum = atoi(argv[2]);
if (strcmp(argv[1], "-d") == 0)
{
int count = -1;
do
{
int c = cin.get();
count++;
if(count == nullNum)
{
cout.put(c);
count = -1;
}
} while (!cin.eof()) ;
}
if(strcmp(argv[1], "-e") == 0)
{
char c = cin.get();
while(!cin.eof())
{
for (int i = -1; i < (nullNum-1); ++i)
{
cout << nullChar();
}
cout << c;
c = cin.get();
}
}
}
代码编译完美。我怀疑循环中的某些东西,但我无法弄清楚。我也认为它在几天前运行得很好,但现在不是。那可能吗?