[問題] 為何停不下來

看板C_and_CPP (C/C++)作者 (分子小於64)時間16年前 (2010/03/13 22:23), 編輯推噓2(203)
留言5則, 2人參與, 最新討論串1/1
#include <iostream> #include <fstream> using namespace std; int main(){ /* read file */ char *key = "lpokmnjiuhbvgytfcxdreszawq"; ifstream fin("1.3 ciphertext.txt"); if(!fin) cout << "讀檔失敗" << endl; // 檢查讀檔成功與否 char *str, *temp; char ch; temp = str; while(fin.get(ch)!='\0'){ *str = ch; str++; } str = temp; /* start */ while(*str != '\0'){ if(*str!=' ') cout << key[*str - 97]; str++; } system("PAUSE"); //fin.close(); // 關閉檔案 return 0; } 我有加system("pause"); 煩請高手幫忙解惑 謝謝~! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.116.218.120

03/13 22:25, , 1F
str沒new就dereference 沒爆炸嗎
03/13 22:25, 1F

03/13 22:25, , 2F
停的下來吧 只是當機了
03/13 22:25, 2F

03/13 22:27, , 3F
為何要NEW? 想說宣告一個變數就會有位址了 @@
03/13 22:27, 3F

03/13 22:27, , 4F
指導一下吧 感謝~~
03/13 22:27, 4F

03/13 22:28, , 5F
指標要指到一個合法的位址阿 你宣告出來的是&str 自己本身的
03/13 22:28, 5F
文章代碼(AID): #1Bcv_Ynn (C_and_CPP)
文章代碼(AID): #1Bcv_Ynn (C_and_CPP)