【发布时间】:2023-03-09 07:09:02
【问题描述】:
这是用于读取主内存地址痕迹以进行高速缓存模拟的 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# 给出语法错误,因为右移运算符不能应用于字符串运算符。
为什么这不起作用?我正在做一个小型缓存命中和未命中计算项目。
【问题讨论】:
标签: c# c++ operator-overloading iostream