[問題] cin.getline()如何做到重複輸入??
開發平台(Platform): VC++
額外使用到的函數庫(Library Used): iostream
問題(Question):使用字元陣列,再使用cin.getline(),它就不能再重複執行了
餵入的資料(Input):feanor fingolfin hong, y, feanor hong
預期的正確結果(Expected Output):6 16, 6
錯誤結果(Wrong Output):6 16, 按任意鍵繼續
程式碼(Code):(請善用置底文網頁, 記得排版)
#include<iostream>
#include<string>
using namespace std;
int main()
{
char answer;
do
{
int end;
int counterblank = 0;
int blank[2];
char initial[30];
system("cls");
cin.getline(initial,30);
for(int j = 0;j<30;j++)
{
if(initial[j]==' ')
{
blank[counterblank] = j;
counterblank++;
}
if(initial[j]=='\0')
{
end = j;
}
}
if(counterblank==1)
{
for(int g =0;g<1;g++)
{
cout<<blank[g];
blank[g] = 0;
}
}
else
{
for(int h = 0;h<2;h++)
{
cout<<blank[h]<<" ";
blank[h] = 0;
}
}
cout<<endl;
cout<<"Do you want to do it again??(y/others)"<<endl;
cin>>answer;
}while((answer=='y')||(answer=='Y'));
system("pause");
return 0;
}
補充說明(Supplement): string 我之後會拿掉
--
306
長官 , 恕我冒犯 ! 是標緻406 , 應該不是原廠的
白癡 我是說他的速度306
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 42.70.129.34
→
03/16 17:20, , 1F
03/16 17:20, 1F
推
03/16 17:23, , 2F
03/16 17:23, 2F
→
03/16 17:25, , 3F
03/16 17:25, 3F
→
03/16 17:27, , 4F
03/16 17:27, 4F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章