- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
感谢您花时间阅读我的第一个查询。我是 C++ 的新手,老实说我已经筋疲力尽了。我花在寻找支持“线程”的 IDE 上的时间比学习这门语言的时间还多。尝试过 DevC++ 5.5.3、Eclipse 4.3.1,目前正在尝试 Visual Studio Express 2013。我认为我的代码很可靠,但当然我可能是错的。很可能是错误的,也许。这是一个示例:
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <chrono>
#include <ctime>
#include <iomanip>
#include <thread>
#include "IntervalSelection.h"
#include "Acnt.h"
using namespace std;
int main(int argc, char *argv[])
{
cout << "Hello, Mommy. To begin, what is your name?\n";
char NewMommyName[40];
cin >> NewMommyName;
std::thread t1 (Account()), (NewMommyName));
Supply * pS;
std::time_t NewPumpTime = PumpTime(pS);
struct tm * ptm = std::localtime(&NewPumpTime);
std::chrono::steady_clock::time_point TP =
std::chrono::steady_clock::from_time_t(mktime(ptm));
std::this_thread::sleep_until(TP);
std::cout << " The time is now " << std::put_time (TP, "%X")<<"\nTime to pump!";
t1.join();
//The following errors are generated:
//"no instance of function template "std::put_time" matches the argument list"
//"expression must have class type" (t1.join())
//"expected a ';' - on this line: std::thread t1 (Account()), (NewMommyName));
//"left of '.join' must have class/struct/union"
//"syntax error : ')' - on this line: std::thread t1 (Account()), (NewMommyName));
//error C2040: 'NewMommyName' : 'std::thread' differs in levels of indirection
//from 'char [40]'
似乎有很多比我经验丰富的人提示找不到线程支持。是我的错误还是我无法解决的错误?有没有我可以使用的 IDE,可以减少这方面的麻烦?
下面是两个头文件中更重要的部分以及我在尝试构建时遇到的错误:
#ifndef ACNT_H
#define ACNT_H
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <chrono>
#include <ctime>
#include <iomanip>
#include <thread>
#include "IntervalSelection.h"
using namespace std;
inline
std::string timeString(const std::chrono::steady_clock::time_point& tp)
{
std::time_t t = std::chrono::steady_clock::to_time_t(tp);
std::string ts = ctime(&t);
ts.resize(ts.size() - 1);
return ts;
}
inline
std::chrono::steady_clock::time_point MakeTime(int year, int mon, int day, int
hour, int min, int sec = 0)
{
struct std::tm t;
t.tm_sec = sec;
t.tm_min = min;
t.tm_hour = hour;
t.tm_mday = day;
t.tm_mon = mon - 1;
t.tm_year = year - 1900;
t.tm_isdst = -1;
std::time_t tt = std::mktime(&t);
if (tt == -1){ throw "Not a valid system time."; }
return std::chrono::steady_clock::from_time_t(tt);
}
class Supply
{
friend time_t PumpTime(Supply*);
public:
Supply()
{
double MilkOz = 0.0;
long long tempInterval = 0;
char* dayOrnight;
int year, mon, day, hour, min, sec = 0;
char morning[5] = "a.m.";
char evening[5] = "p.m.";
cout << "\nHow many ounces of milk do you currently have in your
supply?\n";
cout << "For greater accuracy, feel free to enter this value in decimal
form (e.g. 4.5): ";
cin >> MilkOz;
cout << "\nIdeally, how often would you like to pump?\n";
tempInterval = IntervalSelection();
std::chrono::steady_clock::time_point NOW =
std::chrono::steady_clock::now();
time_t currentTp = std::chrono::steady_clock::to_time_t(NOW);
struct tm* local;
local = localtime(¤tTp);
switch (local->tm_hour){ case 12: dayOrnight = evening; break; case 0:
local->tm_hour = (local->tm_hour) + 12; dayOrnight = morning; break; }
if (local->tm_hour > 12){ local->tm_hour = (local->tm_hour) - 12;
dayOrnight = evening;; }
else if (local->tm_hour < 12){ dayOrnight = morning; }
printf("The time is now %d: %d: %d %s", local->tm_hour, local->tm_min,
local->tm_sec, dayOrnight);
cout << "\n";
std::chrono::steady_clock::time_point tNew =
std::chrono::steady_clock::from_time_t(currentTp);
static std::chrono::steady_clock::time_point tt = tNew +
std::chrono::hours(tempInterval);
std::time_t structable, structable2 =
std::chrono::steady_clock::to_time_t(tt);
struct tm* localNew;
localNew = localtime(&structable);
switch (localNew->tm_hour){ case 12: dayOrnight = evening; break; case 0:
localNew->tm_hour = (localNew->tm_hour) + 12; dayOrnight = morning; break; }
if (localNew->tm_hour > 12){ localNew->tm_hour = (localNew->tm_hour) - 12;
dayOrnight = evening; }
else if (localNew->tm_hour < 12){ dayOrnight = morning; }
printf("Your new pump time is scheduled for %d: %d: %d %s",
localNew->tm_hour, localNew->tm_min, localNew->tm_sec, dayOrnight);
cout << "\nTo accept this time enter 'yes'. To specify a different time,
enter 'no'.\n";
char choice[4];
const char* yes = "yes";
const char* no = "no";
cin >> choice;
if (strncmp(choice, yes, 1) == 0)
{
std::string date = ctime(&structable);
date.resize(date.size() - 1);
cout << "Thank you. Your next pump time is confirmed for " << date;
std::time_t tpNewest = structable2;
}
else if (strncmp(choice, no, 1) == 0)
{
cout << "Please enter an exact date to schedule your next pump
time.\n";
cout << "Enter the current year: ";
cin >> year;
cout << "\nEnter a numerical value for the month. For example, the
number one is equivalent to the month of January: ";
cin >> mon;
cout << "\nEnter the numerical day of the month: ";
cin >> day;
cout << "\nEnter the hour: ";
cin >> hour;
cout << "\nEnter the minutes: ";
cin >> min;
static auto tpNew = MakeTime(year, mon, day, hour, min, sec);
cout << "Your next pump time is scheduled for " <<
timeString(tpNew) << endl;
std::time_t tpNewest = std::chrono::steady_clock::to_time_t(tpNew);
}
}
double entry = 0;
double getSupply(double MilkOz, double entry)
{
TotalSupply = MilkOz + entry;
return TotalSupply;
}
~Supply(){}
private:
double TotalSupply;
std::time_t tpNewest;
};
time_t PumpTime(Supply* pS)
{
return pS->tpNewest;
}
class Baby
{
public:
Baby()
{
double lbs = 0.0;
double oz = 0.0;
char pbName[40];
char pbGender[40];
cout << "\nWhat is your Baby's name?" << endl;
cin >> pbName;
strncpy(BabyName, pbName, 40);
cout << "And is " << this->BabyName << " a Boy or a Girl?\n";
cin >> pbGender;
strncpy(BabyGender, pbGender, 5);
if (strncmp(this->BabyGender, "boy", 1) == 0)
{
cout << "\nWhat is his weight in pounds and ounces?\n";
cout << "For example: My baby weighs 16 lbs and 4 oz. \n";
cout << "Pounds: ";
cin >> lbs;
cout << "\n Ounces: ";
cin >> oz;
Baby::getWeight(lbs, oz);
}
else if (strncmp(this->BabyGender, "girl", 1) == 0)
{
cout << "\nWhat is her weight in pounds and ounces?" << endl;
cout << "For example: My baby weighs 16 lbs and 4 oz. \n";
cout << "Pounds: ";
cin >> lbs;
cout << "\nOunces: ";
cin >> oz;
Baby::getWeight(lbs, oz);
}
cout << "\n" << this->BabyName << "'s current weight is " <<
this->BabyWeight << " pounds";
}
double getWeight(double pounds, double ounces)
{
ounces = ounces * 1 / 16;
BabyWeight = pounds + ounces;
return BabyWeight;
}
~Baby(){}
private:
char BabyName[40];
char BabyGender[5];
double BabyWeight;
};
class Mommy
{
public:
Mommy(char* paName)
{
strncpy(MommyName, paName, 40);
}
~Mommy(){}
private:
char MommyName[40];
Baby b;
Supply s;
};
class Account
{
public:
Account(char* paName) :m(paName)
{
strncpy(Name, paName, 40);
}
~Account(){}
private:
char Name[40];
Mommy m;
};
#endif
//ERRORS:
//expression must have class type -t1.join();
//expected a type specifier -std::thread t1 (Account()), (NewMommyName));
//left of '.join' must have class/struct/union
//syntax error : '(' -std::thread t1 (Account()), (NewMommyName));
最佳答案
您在这一行中有额外的括号(包括未闭合的括号):
std::thread t1 (Account()), (NewMommyName));
应该是:
std::thread t1 (Account, (NewMommyName));
此外 - 您调用 std::put_time是不正确的。 put_time
采用 const std::tm*
而不是 time_point
。您需要将其转换为 std::tm
才能将其传递给 put_time
如果没有其余代码,就很难诊断出这对错误。我怀疑您的问题不是编译器支持。
关于c++ - 是否有提供 C++ <Thread> 支持的 IDE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20648919/
我开发了一个具有基本安全性的 Spring Boot 应用程序。我有两个具有相同路径和不同 http 方法的端点。当我使用默认密码/使用 application.yml 中给出的密码包含基本安全性时,
我的代码是这样的: 或者,像这样: 如果我首先列出 webm 源,Firefox 4 会播放它,但 Firefox 3.6 也会尝试播放它(但会失败,因为它不支持 webm)。
我希望提供一个泛型类型作为类型参数而不首先将其解析为具体类型。换句话说,我正在寻找一种方法来指定从基类继承时可以使用的类型映射函数。 示例(不正确的)语法,希望比我能解释得更好: abstract c
我在 .NET 中编写了一些桌面应用程序,它们既提供了用于正常使用的前端 GUI,也提供了用于其他需求(例如扩展、调度、自动化、高级使用等)的命令行界面。命名两个可执行文件的最佳做法是什么,因为它们构
我最近在这里思考了很多关于屏幕抓取以及它可能是一项什么样的任务。所以我提出以下问题。 作为网站开发人员,您是否会公开简单的 API 以防止用户抓取屏幕,例如 JSON 结果? 然后这些结果可以实现缓存
我正在为一个项目使用 Dojo 1.9,但我不明白 dojo.provide 的正确替代方案与传统风格相比,AMD 风格。我正在阅读 this文档页面。 很明显,这就是旧语法映射到新语法的方式: 旧
我正在开发一个 Angular 应用程序。当我使用 ng serve 正常运行它时,它运行没有任何错误.但是,当我运行 ng build --prod ,它给出了以下错误。 ERROR in Ille
我有一个 Mac 应用程序。在我的 Mac 应用程序中,我的屏幕之一有一个包含文本字段的 scrollView。在同一屏幕上,我有一个需要提供打印选项的按钮。可以打印文本字段的文本。打印按钮应调用 M
我已经成功地为普通媒体文件提供媒体文件,但是当我尝试提供管理媒体文件时,我失败了。请帮我找出问题所在,因为我已经尝试解决问题几个小时但没有运气(也一直在谷歌搜索并阅读有关提供静态文件的 django
我正在尝试创建一个简单的错误处理项目,它会在收到错误(例如 404、422 或 500)后为 JSON 提供错误数据。我使用来自 this 的代码网站,但它不适合我。 我实际上有这两个类: 基本 Co
假设我有一个名为 Number 的类(class),我打算对 Number 进行大量相等比较对象。我担心通用 Number::equals(Object o) 的“开销”(类比较等...)方法。在这种
假定以下情况: 对等方A只希望将音频流发送给对等方B 对等B只希望将视频流发送给对等A 从而, 与创建报价 var sdpConstraints = { “必填”:{ 'OfferToReceiveA
因为我有一些角度,所以我想检查角度模数 360°: double angle = 0; double expectedAngle = 360; angle.Should().B
这是我的程序中构建的 monad 堆栈: type Px a = ReaderT PConf (State PState) a 其中 PConf 和 PState 是保存应用程序的配置和状态的任意数据
因为我有一些角度,所以我想检查角度模数 360°: double angle = 0; double expectedAngle = 360; angle.Should().B
我有一个小程序需要以某些权限运行,这意味着加载时会显示一条警告消息。如果用户拒绝警告消息,我想重定向到错误页面并解释发生了什么。有什么办法可以做到这一点吗? 我研究过让计时器运行并在特定时间段后重定向
从我可以从 Firebase 文档中推断出,似乎需要服务器来提供静态内容(html和 javascript),所以你需要有一台托管机器和一个静态内容服务器在某处启动并运行,或某些服务托管静态站点。 对
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 3 年前。 Improv
我的项目根目录的静态文件夹中有一个文本文件。 我想提供它,所以我创建了: @csrf_exempt def display_text(request): content = retur
我目前正在研究指针,为了进一步理解我正在尝试使用指针将两个数值数组连接成一个。代码如下所示。 #include void concat(int **pa,int **pb,int **pc) {
我是一名优秀的程序员,十分优秀!