好吧,这就是我想做的,我的总体目标是创建一个狙击机器人来狙击(使用的术语是("OG用户名";我目前正在头文件中使用一个结构,我这样做的原因是为了减少代码重复,使程序更有效地运行。我的总体目标是从网页中提取时间戳,并以毫秒为单位计算运行任务的确切时间。
在头文件中,它有这样的:
struct TimeTilNameDrop
{
int days; //Integer for days
int hours; //Integer for hours
int minutes; //Integer for minutes
int seconds; //Integer for seconds
int miliseconds; //Integer for miliseconds
};
我试图用天、小时、分钟、秒来获取用户的输入,但我无法计算毫秒,我很感激这是不准确的,因为程序运行任务的时间需要几毫秒,我需要考虑这一点。
#pragma warning(disable : 4996)
#include <iostream>
#include <ctime>
#include <time.h>
#include <NameDropData.h> //The headerfile containing the struct
using namespace std;
//Linker Decleration.
struct TimeTilNameDrop;
void Test(TimeTilNameDrop);
int TurboSnipe(Test)
{
cout << "Please enter the days til name drop";
cin >> days;
cout << "Please enter the hours til name drop";
cin >> hours;
cout << "Please enter the minutes til name drop";
cin >> minutes;
cout << "Please enter the seconds til name drop";
cin >> seconds;
}
我试过看其他教程,其中结构被放在头文件中,我知道它可能在本地类中工作。然而,我喜欢效率的概念。如有任何帮助,我们将不胜感激。
p.S我是一个傻瓜,这是我的第一个项目。我知道它可能不起作用,或者我可能没有能力,但我认为这将是一个很好的项目
哦,如果有人对C++的任何好的视频课程有任何建议,欢迎提出建议,我目前一直在做"Cherno的">C++系列,我刚刚学会了指针是如何工作的。
欢迎建议:(
我假设您正试图根据您的描述将信息存储到结构中。我注意到您当前所做的工作的主要问题是,您从未创建过结构的实例。您需要创建一个结构的实例来在其中存储信息。下面是一个如何做到这一点的例子:
//header file where stuct is
#include "stackOverflow.h"
//linker declaration for struct
struct TimeTilNameDrop;
using namespace std;
int main() {
//create an instance of the stuct named timeStruct
TimeTilNameDrop timeStruct;
cout << "Please enter the days til name drop"<<endl;
cin >> timeStruct.days;
cout << "Please enter the hours til name drop"<<endl;
cin >> timeStruct.hours;
cout << "Please enter the minutes til name drop"<<endl;
cin >> timeStruct.minutes;
cout << "Please enter the seconds til name drop"<<endl;
cin >> timeStruct.seconds;
return 0;
}