首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >参考c++中的时间函数

参考c++中的时间函数
EN

Stack Overflow用户
提问于 2021-07-20 11:44:39
回答 1查看 144关注 0票数 0

我正在处理一个函数,该函数相应地重写时间结构的值(如果分钟为128,它将更改为2小时8分钟)。

现在不要太在意实际的函数,我的问题似乎是声明/参数/struct本身。

Erors:

ambiguous

  • Error (active) E0070不完全类型不允许

  • 错误(active) E0266 "time“是

  • (active) E0065预期的';'

我做错了什么?

谢谢。

代码语言:javascript
复制
#include<iostream>
#include<iomanip>
//#include<math.h>
//void canonify(time&);
using namespace std;
//
typedef struct time
{
    int h, min, sec;
};
//
const int full = 60;
//
void canonify(time& pre)  // eror1 and eror2
{                         // eror3
pre.min += pre.sec / full;
pre.h += pre.min/ full;
pre.sec %= full;
pre.min %= full;
}
void main()
{
    time a;
    a.h = 3;
    a.min = 128;
    a.sec = 70;
    canonify(a);
    cout << a.h <<":"<< a.min <<":"<< a.sec << endl;
}
EN

Stack Overflow用户

回答已采纳

发布于 2021-07-20 11:59:20

结构名'time‘正在引起冲突。您可以将struct的名称更改为其他内容,并将替换为struct,否则编译器本身将忽略该结构。

这段代码对我有用。

代码语言:javascript
复制
#include <iostream>
#include <iomanip>
//#include<math.h>
//void canonify(ti&);
using namespace std;
//
struct ti                               //change
{
    int h, min, sec;
};
//
const int full = 60;
//
void canonify(ti &pre)                 //change
{
    int hour;
    int minute;
    int second;
    minute = pre.sec / full;
    second = minute * full - pre.sec;
    hour = pre.min / full;
    minute = hour * full - pre.min;
    pre.h = hour;
    pre.min = minute;
    pre.sec = second;
}
int main()
{
    ti a;                              //change
    a.h = 3;
    a.min = 128;
    a.sec = 70;
    canonify(a);
    cout << a.h << ":" << a.min << ":" << a.sec << endl;
}
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68454294

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档