1樓:匿名使用者
cstring tempimeisn=「21」; //字串int imeisn=0;
imeisn=atoi(tempimeisn);
imeisn=imeisn+1020;
tempimeisn.format("%d",imeisn); //整型數用%d,不是%f
tempimeisn.format("%07s",tempimeisn);
2樓:匿名使用者
改cstring tempimeisn="21";試試
3樓:匿名使用者
cstring tempimeisn=_t("21");
int imeisn= 0;
imeisn=_ttoi(tempimeisn);
imeisn=imeisn+1020;
tempimeisn.format(_t("%d"),imeisn);//為什麼結果是0000而不是1041
tempimeisn.format(_t("%s"),tempimeisn);
這是乙個可執行程式,結果是1041
你上面有兩個問題1.不能把21直接賦給cstring;
2.%d才是整形的轉換標誌,%f是浮點型的轉換標誌。
mfc cstring轉int 遇到的問題,請指教
4樓:
看你使用這個函式:setwindowtextw,就知道你是在unicode環境下寫的**,所以的程式應該改成:
cstring nr1;
bj.getwindowtext(nr1);
int a=_ttoi(nr1);
cstring q;
q.format(_t("%d"),a);
bj2.setwindowtext(q);
5樓:溫暖
cstring nr1;
bj.getwindowtextw(nr1);//nr1是從bj文字框中獲得數值
int a = = _ttoi(ab);//將cstring ->int
cstring q;
q.format(_t("%d"),a);//int->cstring
bj2.setwindowtextw(q); //將bj2的值設定為q
6樓:相思丶貓
cstring轉int:非unicode環境cstring str("1234");
char *ch = str.getbuffer(str.getlength());
int num = atoi(ch);
str.releasebuffer();
int轉cstring:非unicode環境cstring str;
int num = 1234;
str.format("%d",num);
不建議使用(lpstr)(lpctstr)這樣的轉換,不安全,錯誤率高。
初學c++,寫了乙個c++運算子過載的程式還沒結束就呼叫了析構?程式求指教修改!
7樓:匿名使用者
運算子過載函式裡有乙個作為結果的cstring物件,函式返回時用這個物件得到返回值(拷貝構造)然後把這個物件析構
主要問題是new char申請陣列,別用小括號,沒過載賦值運算子,可以改成cstring s3("c++" + (s1 + s2));
8樓:匿名使用者
mfc問題int轉,MFC問題int轉cstring
一般如果是將 int 轉換成 cstring 型別,一般就是用 format 函式方法如下 cstring str int a 15 str.format d a 如果是將 int 轉換為 char 型別就需要用到 itoa 這個函式方法如下 char chr 1024 int a 15 itoa ...
c語言int型資料轉char型資料,就是將int的高低兩
unsigned int y 定義乙個無符號整形 unsigned char m,n 定義兩個長度為8位的變數 m y 8 將資料向右移動八位,那麼高位的話就全部是0了,然後將乙個int型別的資料傳遞給乙個char型別的資料 n y 直接將int資料傳遞給char型別,這裡將會發生資料丟失 int ...