小编use*_*382的帖子

如何修复C++编译器错误"无法将'Type'转换为'const Type*'"?

这是完整的错误消息:

错误:无法将'MyTime'转换为'const MyTime*'以将参数'1'转换为'int DetermineElapsedTime(const MyTime*,const MyTime*)'|

这是我的代码:

#include <iostream>
#include<cstdlib>
#include<cstring>

using namespace std;
struct MyTime { int hours, minutes, seconds; };
int DetermineElapsedTime(const MyTime *t1, const MyTime *t2);
const int hourSeconds = 3600;
const int minSeconds = 60;

int DetermineElapsedTime(const MyTime *t1, const MyTime *t2)
{
    long timeDiff = ((((t2->hours * hourSeconds) + (t2->minutes * minSeconds) + t2->seconds) -
                   ((t1->hours * hourSeconds) + (t1->minutes * minSeconds) + t1->seconds)));
    return(timeDiff);
}


int main(void)
{
    char delim1, delim2;
    MyTime tm, tm2; …
Run Code Online (Sandbox Code Playgroud)

c++ constructor pointers compiler-errors

5
推荐指数
1
解决办法
2万
查看次数

如何在没有System.exit的情况下退出Java程序?(来自用户输入?)

这是我的代码.我不知道如何使用返回值退出程序.有任何想法吗?这是我任务的最后一步.重要的区域标有///////我听到返回工作但是当我将main中的void更改为int时,程序说main必须是void.

import java.util.Scanner;


public class CommissionCalculator {

    public static void main(String args[]) {
        // Initialize a Scanner to read input from the command line
        Scanner ItemSelect = new Scanner(System.in);
        double comp = 200.00;
        double item1 = 239.99;
        double item2 = 129.75;
        double item3 = 99.95;
        double item4 = 350.89;
        double comm = 0.09;
        int choice;


        /* Note that we'll be doing this at least once and most likely multiple times...
         * Prompt the user with a menu of the four …
Run Code Online (Sandbox Code Playgroud)

java

3
推荐指数
1
解决办法
4万
查看次数

如何使用条件语句返回指针?

以下代码输出第二个数字作为最大值.如果您需要任何其他信息,请告诉我.

#include <iostream>                                                     
#include <cstdlib>
using namespace std;
double *ComputeMaximum(const double *Max, const double *Min);

double *ComputeMaximum(const double *Max, const double *Min)
{
    return ((double *)((&Max > &Min) ? Max : Min));
}

int main(void)
{
    double *max;
    double Initial, Secondary;


    cout << "Enter the number followed by space then another number: ";
    cin >> Initial;
    cout << "\nIn-" << Initial;
    cin >> Secondary;
    cout << "\nSe-" << Secondary;
    //cout >> "Of " >> Inital >> "and " >> Secondary; …
Run Code Online (Sandbox Code Playgroud)

c++ pointers conditional-statements

2
推荐指数
2
解决办法
196
查看次数

如何在C++中正确使用setfill()?

所以我现在已经解决了这个问题一段时间了,在成员的帮助下,我差不多完成了.我的上一个问题是上面的问题.

如果需要,我需要将cout时间格式化为01:01:01,但是,我的输出是1:1:1

问题出在这里:

std::ostream& operator<< (ostream& os, const MyTime& m)
{
    os << setfill('0') << m.hours << ":" << setfill ('0') << m.minutes << ":" << setfill ('0') << m.seconds;
    return os;
}
Run Code Online (Sandbox Code Playgroud)

这是整个代码.

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <iomanip>


using namespace std;
struct MyTime { int hours, minutes, seconds; };
MyTime DetermineElapsedTime(const MyTime *t1, const MyTime *t2);

const int hourSeconds = 3600;
const int minSeconds = 60;
const int dayHours = 24;
const char zero = 0; …
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
5651
查看次数