Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual c++ 必须具有类/结构/联合 你好,我正在为学校做作业,但我遇到了一些问题,我是C++初学者,并不熟悉它。我真的很感谢到目前为止给我的帮助,但是我仍然在第31-35行遇到错误 error C2228: left of '.substr' must have class/struct/union error C2228: left of '.c_str' must have class/struct/union_Visual C++ - Fatal编程技术网

Visual c++ 必须具有类/结构/联合 你好,我正在为学校做作业,但我遇到了一些问题,我是C++初学者,并不熟悉它。我真的很感谢到目前为止给我的帮助,但是我仍然在第31-35行遇到错误 error C2228: left of '.substr' must have class/struct/union error C2228: left of '.c_str' must have class/struct/union

Visual c++ 必须具有类/结构/联合 你好,我正在为学校做作业,但我遇到了一些问题,我是C++初学者,并不熟悉它。我真的很感谢到目前为止给我的帮助,但是我仍然在第31-35行遇到错误 error C2228: left of '.substr' must have class/struct/union error C2228: left of '.c_str' must have class/struct/union,visual-c++,Visual C++,这是我的作业 停车场停车三小时的最低收费为2美元。车库每超过三小时,每小时或不足一小时,每小时额外收费0.50美元。最高收费 任何给定的24小时期限为$10.00。停车超过24小时的人每天将支付8美元。 编写一个计算和打印停车费的程序。程序的输入是汽车进入停车场的日期和时间,以及同一辆汽车离开停车场的日期和时间。两种输入的格式均为 YY/MM/DD hh:MM #include <iostream> #include <fstream> #include <ioma

这是我的作业 停车场停车三小时的最低收费为2美元。车库每超过三小时,每小时或不足一小时,每小时额外收费0.50美元。最高收费 任何给定的24小时期限为$10.00。停车超过24小时的人每天将支付8美元。 编写一个计算和打印停车费的程序。程序的输入是汽车进入停车场的日期和时间,以及同一辆汽车离开停车场的日期和时间。两种输入的格式均为
YY/MM/DD hh:MM

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <sstream>
using namespace std;

int dateStr;
int parseDate( std::string dateStr );

int main ()

{
int enter_date;
int enter_time;
int exit_date;
int exit_time;
cout << "Please enter the date and time the car is entering "<< endl
    << "the parking garage in the following format: YY/MM/DD hh:mm"<< endl;
 cin >> enter_date >> enter_time;


cout<< "Please enter the date and time the car is exiting "<< endl
    << "the parking garage in the following format: YY/MM/DD hh:mm"<< endl;
cin >> exit_date >> exit_time;

{
    // Format: YY/MM/DD hh:mm
    int year  = atoi( dateStr.substr( 0, 2 ).c_str() );
    int month = atoi( dateStr.substr( 3, 2 ).c_str() );
    int day   = atoi( dateStr.substr( 6, 2 ).c_str() );
    int hour  = atoi( dateStr.substr( 9, 2 ).c_str() );
    int min   = atoi( dateStr.substr( 12, 2 ).c_str() );

    // Now calculate no. of mins and return this
    int totalMins = 0;
    totalMins += ( year * 365 * 24 * 60 ); // Warning: may not be accurate enough
    totalMins += ( month * 30 * 24 * 60 ); // in terms of leap years and the fact
    totalMins += ( day * 24 * 60 );        // that some months have 31 days
    totalMins += ( hour * 60 );
    totalMins += ( min );

    return totalMins;
}

return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
int-dateStr;
int-parseDate(std::string-dateStr);
int main()
{
输入日期;
输入时间;
int exit_日期;
int退出时间;
无法输入时间;
不能及时退出;
{
//格式:年月日hh:MM
int year=atoi(dateStr.substr(0,2.c_str());
intmonth=atoi(dateStr.substr(3,2.c_str());
intday=atoi(dateStr.substr(6,2.c_str());
inthour=atoi(dateStr.substr(9,2.c_str());
intmin=atoi(dateStr.substr(12,2.c_str());
//现在计算分钟数并返回此值
整数totalMins=0;
totalMins+=(年份*365*24*60);//警告:可能不够准确
totalMins+=(月*30*24*60);//根据闰年和事实
totalMins+=(天*24*60);//某些月份有31天
总分钟+=(小时*60);
总分钟数+=(分钟);
返回totalmin;
}
返回0;
}

您将
dateStr
声明为
int
。它应该是一根绳子吗?您可能也应该初始化它。

我真的不确定。。。我试着把它改成字符串,但似乎没有用。也许我做错了?我还以为我在它前面加了int来初始化它,是不是错了?听起来你需要回到基础。试着做一个小程序,然后完成你的任务。我已经做了不到一个月了,完全认为这是“基础”。。。。所以我把它改成了一个字符串,就像你说的,但是我现在得到了这个错误。。。此应用程序已请求运行时以异常方式终止它。有关更多信息,请联系应用程序的支持团队。