简体   繁体   English

C++ 程序未运行

[英]C++ program is not running

I'm new to C++ and i wrote today the following program:我是 C++ 的新手,我今天写了以下程序:

#include <iostream>
using namespace std;

typedef struct item
{
    int hour;
    int minute;
    int second;

    void print()
    {
        cout << hour << ":" << minute << ":" << second << endl;
    }

}time;

time nirmul_time(time a);
time* timing_array(int size);
void print_times(time* array, int size);

int main()
{
    time* our_array;
    int size;

    cout << "Give me the size of the array: " << endl;
    cin >> size;

    our_array = timing_array(size);
    print_times(our_array, size);

    delete[]our_array;
}

time nirmul_time(time a)
{
    a.minute = a.minute + (a.second / 60);
    a.second = a.second % 60;
    a.hour = a.hour + (a.minute / 60);
    a.minute = a.minute % 60;
    a.hour = a.hour % 24;

    return a;
}

time* timing_array(int size)
{
    int i = 0;
    bool overflow = false;
    time* array;
    array = new time[size];

    for (i; i < size; i++)
    {
        cout << "enter the hours: " << endl;
        cin >> array[i].hour;
        if (array[i].hour > 23)
            overflow = true;
        cout << "enter the minutes: " << endl;
        cin >> array[i].minute;
        if (array[i].minute > 59)
            overflow = true;
        cout << "enter the seconds: " << endl;
        cin >> array[i].second;
        if (array[i].second > 59)
            overflow = true;

        if (overflow)
        {
            nirmul_time(array[i]);
        }

        overflow = false;
    }

    return array;
}

void print_times(time* array, int size)
{
    int i = 0;
    for (i; i < size; i++)
    {
        array[i].print();
    }
}

when i try to run it throught ctrl+F9 or ctrl+F5 the program is not running, and i get the following error:当我尝试通过 ctrl+F9 或 ctrl+F5 运行它时,程序没有运行,我收到以下错误:

1>------ Build started: Project: Project1, Configuration: Debug Win32 ------
1>Source.cpp
1>Project1\Project1\Source.cpp(1,1): warning C4335: Mac file format detected: please convert the source file to either DOS or UNIX format
1>Project1\Project1\Source.cpp(1,10): warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>Project1\Project1\Source.cpp(2,1): error C2447: '{': missing function header (old-style formal list?)
1>Project1\Project1\Source.cpp(6,504): error C2065: 'time': undeclared identifier
1>Project1\Project1\Source.cpp(6,510): error C2065: 'array': undeclared identifier
1>Project1\Project1\Source.cpp(6,521): error C2062: type 'int' unexpected
1>Project1\Project1\Source.cpp(6,527): error C2143: syntax error: missing ';' before '{'
1>Project1\Project1\Source.cpp(6,527): error C2447: '{': missing function header (old-style formal list?)
1>Done building project "Project1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

also when i try to run in through debugger ctrl+F5 i get an error message: enter image description here同样,当我尝试通过调试器 ctrl+F5 运行时,我收到一条错误消息:在此处输入图像描述

i tried to reopen the project, and to run it in online shell but still it does not work, can somebody help me detect the problem?我试图重新打开该项目,并在线运行它 shell 但它仍然不起作用,有人可以帮我检测问题吗?

The name you tried to give to the structure time is already taken by the standard library .您尝试为结构time指定的名称已被标准库使用。

You should give it another name.你应该给它另一个名字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM