-->

How do I preserve a comment in an example in Doxyg

2020-08-01 06:19发布

问题:

I have a simple method with a comment I want to use as an example in my doxygen mainpage:

\code

    void showNum(int numToDisplay){

        // This is just a method to display a value.
        std::cout<<"Displaying Number "<<numToDisplay<<std::endl;
    }

\endcode

When a generate the docs, the mainpage will show the code example correctly but the comment will be all the way to the left edge of the main page. What character(s) do I use to force the comment to maintain its justification and display?

Thanks in advance for the help.

回答1:

Without a little more information it's going to be hard to diagnose this but a couple things to check :

  • Make sure you have a blank line preceding your code.
  • Make sure that you have four spaces indentation
  • Make sure the white space preceding your comment is not a tab

It sounds as if your code is not being interpreted as a code block (because of one of the reasons listed above). If you could post at least part of the file with the code block in it, it might help sort this out.

Here's a small example which seems to do what you want:

/**
 * @file tmp.cpp
 */

/** Brief description
 *
 * Long description of what the function does ...
 *
 * \code{.cpp}
 *
 *     void showNum(int numToDisplay){
 *
 *         // This is just a method to display a value.
 *         std::cout<<"Displaying Number "<<numToDisplay<<std::endl;
 *     }
 *
 * \endcode
 *
 */
void showNum(int numToDisplay) {
   std::cout << "Displaying Number " << numToDisplay << std::endl;
}


标签: c++ doxygen