【发布时间】:2014-12-03 22:22:20
【问题描述】:
#include <stdio.h>
#include <iostream.h>
#include <string.h>
int main()
{
char P_input[101];
int Bug_Time[10][4];
int Tot_Time[4];
char rimp[10];
cout<<"Enter Total time:"<<endl;
cin.getline(P_input,100);
cout<<P_input<<endl;
sscanf(P_input, "%d Days - %d - Hours - %d - Minutes - %d Seconds", Tot_Time[0],Tot_Time[1],Tot_Time[2],Tot_Time[3]);
cout<<Tot_Time[0]<<Tot_Time[1]<<Tot_Time[2]<<Tot_Time[3]<<endl;
return 0;
}
返回输出
> Enter Total time:
> 0 Days - 0 - Hours - 26 - Minutes - 56 Seconds //I entered this
> 0 Days - 0 - Hours - 26 - Minutes - 56 Seconds // It showed me this
> 1576 1558 0 7762 //Final cout
有人可以帮我解决这个问题吗?我希望它显示“0 0 26 56”
【问题讨论】:
-
实际上只使用
std::istringstream有什么问题? -
sscanf 采用指向其输出参数的指针。还有更好的 C++ 方法可供使用(编辑:请参阅@πάνταῥεῖ 评论以获得更有用的 C++ 方法)。