Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/128.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 整数未正确递增_C++_String_Int_Hex_Mips - Fatal编程技术网

C++ 整数未正确递增

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

好的,我目前正在尝试实现一个MIPS程序计数器,它包括我存储一个十六进制值,以跟随程序所在的位置(程序计数器)。但问题是以下代码不会超过个位数,因为它会递增,即0,4,8,0等,其中重复的0应等于10

如果str_pc初始设置为000000 10,则此源可以工作,否则将不工作

#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;