[問題] system("PAUSE")

看板C_and_CPP (C/C++)作者 (多情種子)時間16年前 (2010/03/10 23:38), 編輯推噓0(0011)
留言11則, 3人參與, 最新討論串1/1
想請問一下 如果就算加上system("PAUSE") 他還是不等我閃一下就過去(依稀看到裡頭有正確結果) 那是什麼問題呢 我只是試試看compile程式書上附的光碟裡頭的程式 還是他有版權不讓我compile呢? <code from "how to program 5th"> #include <iostream> #include <stdlib.h> #include <string> using std::string; using std::cout; using std::endl; int main() { string s1( "happy" ); string s2( " birthday" ); string s3; // test overloaded equality and relational operators cout << "s1 is \"" << s1 << "\"; s2 is \"" << s2 << "\"; s3 is \"" << s3 << '\"' << "\n\nThe results of comparing s2 and s1:" << "\ns2 == s1 yields " << ( s2 == s1 ? "true" : "false" ) << "\ns2 != s1 yields " << ( s2 != s1 ? "true" : "false" ) << "\ns2 > s1 yields " << ( s2 > s1 ? "true" : "false" ) << "\ns2 < s1 yields " << ( s2 < s1 ? "true" : "false" ) << "\ns2 >= s1 yields " << ( s2 >= s1 ? "true" : "false" ) << "\ns2 <= s1 yields " << ( s2 <= s1 ? "true" : "false" ); // test string member function empty cout << "\n\nTesting s3.empty():" << endl; if ( s3.empty() ) { cout << "s3 is empty; assigning s1 to s3;" << endl; s3 = s1; // assign s1 to s3 cout << "s3 is \"" << s3 << "\""; } // end if // test overloaded string concatenation operator cout << "\n\ns1 += s2 yields s1 = "; s1 += s2; // test overloaded concatenation cout << s1; // test overloaded string concatenation operator with C-style string cout << "\n\ns1 += \" to you\" yields" << endl; s1 += " to you"; cout << "s1 = " << s1 << "\n\n"; // test string member function substr cout << "The substring of s1 starting at location 0 for\n" << "14 characters, s1.substr(0, 14), is:\n" << s1.substr( 0, 14 ) << "\n\n"; // test substr "to-end-of-string" option cout << "The substring of s1 starting at\n" << "location 15, s1.substr(15), is:\n" << s1.substr( 15 ) << endl; // test copy constructor string *s4Ptr = new string( s1 ); cout << "\n*s4Ptr = " << *s4Ptr << "\n\n"; // test assignment (=) operator with self-assignment cout << "assigning *s4Ptr to *s4Ptr" << endl; *s4Ptr = *s4Ptr; cout << "*s4Ptr = " << *s4Ptr << endl; // test destructor delete s4Ptr; // test using subscript operator to create lvalue s1[ 0 ] = 'H'; s1[ 6 ] = 'B'; cout << "\ns1 after s1[0] = 'H' and s1[6] = 'B' is: " << s1 << "\n\n"; // test subscript out of range with string member function "at" cout << "Attempt to assign 'd' to s1.at( 30 ) yields:" << endl; s1.at( 30 ) = 'd'; // ERROR: subscript out of range system("PAUSE"); return 0; } -- 無名網誌(日本生活): http://www.wretch.cc/blog/gigigaga1202 Lang-8: http://lang-8.com/20414 如果你繼續追逐我的幻影 你將被真正的我追上 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 202.71.92.74 ※ 編輯: gigigaga17 來自: 202.71.92.74 (03/10 23:38)

03/10 23:39, , 1F
程式碼貼上來看看
03/10 23:39, 1F
※ 編輯: gigigaga17 來自: 202.71.92.74 (03/10 23:45)

03/10 23:45, , 2F
^^||
03/10 23:45, 2F

03/11 00:04, , 3F
因為最後一段那個錯誤會讓程式直接關閉吧, 把有標 ERROR
03/11 00:04, 3F

03/11 00:05, , 4F
那行砍掉才能執行到 pause 那邊...然後請用 cin.get() 不
03/11 00:05, 4F

03/11 00:06, , 5F
要用 system("PAUSE")
03/11 00:06, 5F

03/11 00:09, , 6F
然後原 po 我好像認識你本人是吧 -_-
03/11 00:09, 6F

03/11 00:10, , 7F
是阿 好像還同班過耶XD 我試試看程式^^
03/11 00:10, 7F

03/11 00:12, , 8F
謝謝 這樣ok了^^ 他剛剛居然沒出現error...
03/11 00:12, 8F

03/11 00:20, , 9F
這種錯誤編譯器看不出來...這個例子告訴你千萬不能讓編號
03/11 00:20, 9F

03/11 00:20, , 10F
超過陣列長度不然就完蛋了 lol
03/11 00:20, 10F

03/11 10:56, , 11F
嗯 上了一課^^ 書上有附程式檔這樣就可以玩看看了
03/11 10:56, 11F
文章代碼(AID): #1Bbxpl_4 (C_and_CPP)
文章代碼(AID): #1Bbxpl_4 (C_and_CPP)