这是用于缓存内存模拟的主存地址跟踪的C++代码:
问题出在
为什么会出错呢?我正在制作一个小的缓存命中和未命中计算项目。
char hex[20];
ifstream infile;
infile.open(filename,ios::in);
if(!infile) {
cout<<"Error! File not found...";
exit(0);
}
int set, tag, found;
while(!infile.eof()) { //Reading each address from trace file
if(base!=10) {
infile>>hex;
address = changebase(hex, base);
} else {
infile>>address;
}
set = (address / block_size) % no_set;
tag = address / (block_size * no_set);
}
我已将其转换为C#代码:
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 >> hex;
address = changebase(hex, @base);
} else {
infile >> address;
}
set = (address / block_size) % no_set;
tag = address / (block_size * no_set);
}
问题出在
infile >> hex;
这一行。
C#会报语法错误,因为移位运算符不能应用于字符串操作符。为什么会出错呢?我正在制作一个小的缓存命中和未命中计算项目。