C++ 整数未正确递增
好的,我目前正在尝试实现一个MIPS程序计数器,它包括我存储一个十六进制值,以跟随程序所在的位置(程序计数器)。但问题是以下代码不会超过个位数,因为它会递增,即0,4,8,0等,其中重复的0应等于10 如果str_pc初始设置为000000 10,则此源可以工作,否则将不工作C++ 整数未正确递增,c++,string,int,hex,mips,C++,String,Int,Hex,Mips,好的,我目前正在尝试实现一个MIPS程序计数器,它包括我存储一个十六进制值,以跟随程序所在的位置(程序计数器)。但问题是以下代码不会超过个位数,因为它会递增,即0,4,8,0等,其中重复的0应等于10 如果str_pc初始设置为000000 10,则此源可以工作,否则将不工作 #include <iostream> #include <iomanip> #include <sstream> #include <string> #include &l
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <map>
using namespace std;
string str_pc = "00000008";
int main(){
int temp_pc;
stringstream ss;
ss << hex <<str_pc;
ss >> dec >> temp_pc;
cout << "Temp_PC: " <<temp_pc<<endl;
temp_pc = temp_pc+4;
ostringstream ss1;
ss1 << hex << temp_pc;
string x(ss1.str());
str_pc = x;
stringstream ss2;
ss2 << hex <<str_pc;
ss2 >> dec >> temp_pc;
cout << "Temp_PC: " <<temp_pc<<endl;
temp_pc = temp_pc+4;
ostringstream ss3;
ss3 << hex << temp_pc;
string y(ss3.str());
str_pc = y;
cout << str_pc <<endl;
}
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
字符串str_pc=“0000000 8”;
int main(){
国际临时个人电脑;
细流ss;
ss>临时pc;
cout十六进制是字符串中数字(整数)的表示形式
ss << hex << str_pc;
ss >> dec >> temp_pc;
完美地修复了它,最明显的总是愚弄我。谢谢=)
ss << str_pc;
ss >> hex >> temp_pc;