我之前发布了类似的代码,但我认为现在这是一个不同的问题。我只是无法弄清楚为什么我的运行代码不会超过“infile open”。(“-e”打印出来,“-d”不打印)我正在尝试打开我的文件,使用命令行选项来确定我是否会打印出一定倍数的字符。
例如,a.out -d 2 < sample.txt将每隔一个字母打印一次。
int main (int argc, char *argv[])
{
   ifstream infile; 
   if (infile.good())
      printf("infile open \n");
   int c;    
   int number = 0;
   int count = 0; 
   string str1 = argv[1];
   string str2 = "-d";
   string str3 = "-e";
   if (str1.compare(str2) == 0)
   { 
      printf("entered -d\n");
      c = infile.get();       
         while(!infile.eof()) {
             number = atoi(argv[2]);  
              if (count == number)
            {
              cout.put(c);
                      count = 0;
                }
                  else
                      count++;
             c = infile.get();         
}//end while 
}//end if
           if (str1.compare(str3) == 0)       
                printf("entered -e\n");
}//end main