title: Porting iostream input code from C++ to C#
body: <p>This is C++ code for reading traces of address of main memory for cache memory simulation:</p>
  
  <pre><code> char hex[20];
   ifstream infile;
   infile.open(filename,ios::in);
   if(!infile) {
      cout&lt;&lt;"Error! File not found...";
      exit(0);
   }
   int set, tag, found;
   while(!infile.eof()) { //Reading each address from trace file
        if(base!=10) {
             infile&gt;&gt;hex;
             address = changebase(hex, base);
        } else {
             infile&gt;&gt;address;
        }
        set = (address / block_size) % no_set;
        tag  = address / (block_size * no_set);
   }
  </code></pre>
  
  <p>I have converted this to C# code:</p>
  
  <pre><code> char[] hex = new char[20];
   FileStream infile=new FileStream(filename, FileMode.Open);
  
   if (infile == null) {
       Console.Write("Error! File not found...");
       Environment.Exit(0);
   }
   int set;
   int tag;
   int found;
   while (!infile.CanRead) { //Reading each address from trace file
       if (@base != 10) {
           infile &gt;&gt; hex;
           address = changebase(hex, @base);
       } else {
           infile &gt;&gt; address;
       }
       set = (address / block_size) % no_set;
       tag = address / (block_size * no_set);
   }
  </code></pre>
  
  <p>The problem is on line <code>infile &gt;&gt; hex;</code>
  C# is giving syntax errors, as shift right operator cannot be applied to string operators.</p>
  
  <p>Why this is not working? I'm making a small cache hit and miss calculation project.</p>