[問題]c=cin.get())!=EOF問題
( *[1m *[m 為色碼,可以按 Ctrl+V 預覽會顯示的顏色 )
( 未必需要依照此格式,文章條理清楚即可 )
遇到的問題: (題意請描述清楚)
一題要把句子倒轉例ffegrg 要變grgeff
希望得到的正確結果:
程式跑出來的錯誤結果:
輸入abcd 他只跑dcb
那a呢?
開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux)
有問題的code: (請善用置底文標色功能)
#include<iostream>//header file
#include<iomanip>
#include<cmath>
using namespace std;
using std::setw;
using std::fixed;
using std::setprecision;
#include<string>
using std::string;
using std::getline;
int main()
{
string set;
int a;
char c;
//getline(cin,set);
//a=set.length();
cout<<"enter ^z to exit"<<endl;
while((c=cin.get())!=EOF)
{
getline(cin,set);
a=set.length();
for(int i=a-1;i>=0;i--)
{
cout<<set[i];
}
我加cout << c;結果正確為何
cout<<endl;
//set.clear();
}
system("pause");
return 0;
}
補充說明:
謝謝回答
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.7.59
※ 編輯: jasonfghx 來自: 140.112.7.59 (12/01 17:54)
推
12/01 19:42, , 1F
12/01 19:42, 1F
→
12/02 22:13, , 2F
12/02 22:13, 2F
推
12/03 00:39, , 3F
12/03 00:39, 3F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章