Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.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
C++ Gcov报告解释_C++_String - Fatal编程技术网

C++ Gcov报告解释

C++ Gcov报告解释,c++,string,C++,String,我正在做《出纳》课程的代码覆盖,我的老师对报告的含义做了非常简短的讲解,我觉得这对我软件工程技能的发展非常重要。因此,我需要您对以下gcov报告的解释提出建议。我将感谢任何有助于我理解gcov的链接或文章 头文件 #ifndef CASHIER_H #define CASHIER_H #include <string> using namespace std; class cashier { public: void setID(string); st

我正在做《出纳》课程的代码覆盖,我的老师对报告的含义做了非常简短的讲解,我觉得这对我软件工程技能的发展非常重要。因此,我需要您对以下gcov报告的解释提出建议。我将感谢任何有助于我理解gcov的链接或文章

头文件

#ifndef CASHIER_H
#define CASHIER_H
#include <string>
using namespace std;


class cashier 
{
public:

        void setID(string);
    string getID();

    void setPassword(string);
    string getPassword();

    void settries(int);
    int gettries();
        void increase_tries();

private:
    string ID;
    string Password;
    int tries;



};

#endif  /* CASHIER_H */
#include "cashier.h"




void cashier::setID(string value)
{
    this->ID = value;
}

void cashier::setPassword(string value)
{

    this->Password = value;

}

string cashier::getID()
{
    return this->ID;
}

string cashier::getPassword()
{
    return this->Password;
}

void cashier::settries(int value)
{
    this->tries=value;
}
int cashier::gettries()
{
    return this->tries;
}
void cashier::increase_tries()
{
    this->tries = this->tries + 1 ;

}
我在命令提示符中键入以下命令,以便在类上使用gcov

gcov -b cashier.gnco
我得到了以下结果

File 'cashier.cpp'
Lines executed:100.00% of 18 //what does the 18 mean 
No branches                  //what does no branches mean
Calls executed:100.00% of 4   // what does 4 mean ??
cashier.cpp:creating 'cashier.cpp.gcov'

File '/usr/include/c++/4.4/bits/basic_string.h' // Where did this come from ??
Lines executed:0.00% of 2
No branches
Calls executed:0.00% of 1
/usr/include/c++/4.4/bits/basic_string.h:creating 'basic_string.h.gcov
我键入以下命令

gcov -f cashier.gnco
我得到了以下结果

Function '_ZN7cashier8settriesEi' // does this refer to the function :settries
Lines executed:100.00% of 3       // my teacher doesnt think so but i feel it refer
                                  //to it , who is correct??

Function '_ZN7cashier8gettriesEv'
Lines executed:100.00% of 2

Function '_ZN7cashier14increase_triesEv'
Lines executed:100.00% of 3

Function '_ZN7cashier11getPasswordEv'
Lines executed:100.00% of 2

Function '_ZN7cashier5getIDEv'
Lines executed:100.00% of 2

Function '_ZNSsaSERKSs'
Lines executed:0.00% of 2

Function '_ZN7cashier11setPasswordESs'
Lines executed:100.00% of 3

Function '_ZN7cashier5setIDESs'
Lines executed:100.00% of 3

File 'cashier.cpp'
Lines executed:100.00% of 18
cashier.cpp:creating 'cashier.cpp.gcov'

File '/usr/include/c++/4.4/bits/basic_string.h'
Lines executed:0.00% of 2
/usr/include/c++/4.4/bits/basic_string.h:creating 'basic_string.h.gcov'
我对结果A的问题

  • 18是什么意思?在执行的
    行中它的意义是什么:18行的100.00%

  • 无分支
    是什么意思

  • 4是什么意思?它在执行的
    调用中的意义是什么:4个调用的100.00%
    ?为什么我在类中有7个函数时有4个函数调用

  • 整段话是什么意思

    File '/usr/include/c++/4.4/bits/basic_string.h'
        Lines executed:0.00% of 2
        No branches
        Calls executed:0.00% of 1
        /usr/include/c++/4.4/bits/basic_string.h:creating 'basic_string.h.gcov
    
  • 我对结果B的问题

  • 所有函数名称等:
    \u ZN7cashier8settriesEi
    。几乎匹配出纳函数名称等:
    void settrys(int)
    。我认为它指的是同样的功能,但我的老师却不这么认为。哪个是正确的

  • 执行的
    行中的3是什么意思:函数
    \u ZN7cashier8settriesEi
    的3的100.00%


  • 阅读手册页。在终端窗口中键入
    man-gcov
    。还有谷歌gcov。网上有说明

    • gcov-b查找分支。您的代码没有分支(没有if语句,没有循环),因此在这里使用-b选项有点毫无意义

    • gcov-f给出了每个函数的摘要。它忽略了分支概率

    关于数字,gcov有时将大括号和大括号计算为可执行语句,有时则不计算。后面有点痛。查看cashier.cpp.gcov文件,查看哪些行已计算,哪些行未计算

    关于诸如ZN7cashier8settriesEi之类的名称:这是
    出纳::settrys(int)
    的损坏名称。通过c++过滤器传递这些名称


    关于/usr/include/c++/4.4/bits/basic_string.h,忽略这些文件。它们不是您的,但它们将出现在gcov输出中。

    关于c++过滤器的好提示!