C++程序未运行
C++ program is not running
我是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();
}
}
当我尝试通过ctrl+F9或ctrl+F5运行它时,程序没有运行,我得到以下错误:
1>------ Build started: Project: Project1, Configuration: Debug Win32 ------
1>Source.cpp
1>Project1Project1Source.cpp(1,1): warning C4335: Mac file format detected: please convert the source file to either DOS or UNIX format
1>Project1Project1Source.cpp(1,10): warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>Project1Project1Source.cpp(2,1): error C2447: '{': missing function header (old-style formal list?)
1>Project1Project1Source.cpp(6,504): error C2065: 'time': undeclared identifier
1>Project1Project1Source.cpp(6,510): error C2065: 'array': undeclared identifier
1>Project1Project1Source.cpp(6,521): error C2062: type 'int' unexpected
1>Project1Project1Source.cpp(6,527): error C2143: syntax error: missing ';' before '{'
1>Project1Project1Source.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 ==========
此外,当我尝试通过调试器ctrl+F5运行时,我会收到一条错误消息:在此处输入图像描述
我试着重新打开这个项目,并在online shell中运行它,但仍然不起作用,有人能帮我检测问题吗?
您试图赋予结构time
的名称已被标准库使用。
你应该给它取另一个名字。
相关文章:
- 运行程序时出现问题
- 分段错误当我试图运行程序时出错
- C++ 每次运行程序时我都会"nan"输出的问题
- 通过 g++ 运行程序时没有这样的文件或目录
- 重新运行程序和字符串流?
- 无法在 VS Code 上使用代码运行程序运行C++文件
- 使用有限的 RAM 运行 c++ 程序
- 继续运行程序而无需任何干预,直到要求退出为止
- 如何在每次运行程序时写入文件的下一行?
- 控制台在运行C ++程序后立即关闭(无需调试)
- 运行程序时找不到共享对象库,但在编译过程中链接了它
- 远程运行程序
- 在 Heroku 上运行 C++ 程序
- 如何在Powershell中运行C++程序,就像CMD一样?
- 为什么与Java和Python相比,使用Cmake运行C++程序每次都需要这么长时间?
- C++随机数生成器通常在 Visual Studio 中运行程序时在 2 次后停止生成数字
- 崇高文本 3 - 在终端中编译并运行 C++ 程序(路径包含空格)
- 我收到阻止我运行程序的警告,但不确定如何解决
- C++ Visual Studio 无法完全运行程序
- 在SIGABRT c ++信号之后继续运行程序