2

I want to select a piece of code in Visual Studio 2017 and comment it. I know I can use CTRL + K, C, but the result is:

    /*fstream in("c:\\users\\hp\\documents\\visual studio 2017\\projects\\inputfile.in");
    if (!in)
    {
        cerr << "can't open input file\n";
        return 1;
    }
    fstream out("outputfile.out", fstream::out);
    if (!out)
    {
        cerr << "can't open output file\n";
        return 1;
    }*/

and what I actually want is

    //fstream in("c:\\users\\hp\\documents\\visual studio 2017\\projects\\inputfile.in");
    //if (!in)
    //{
    //    cerr << "can't open input file\n";
    //    return 1;
    //}
    //fstream out("outputfile.out", fstream::out);
    //if (!out)
    //{
    //    cerr << "can't open output file\n";
    //    return 1;
    //}

How do I do this?
I searched the internet, but I didn't find the answer to this question.

Timʘtei
  • 753
  • 1
  • 8
  • 21

1 Answers1

7

I found myself the answer, but I can explain it only using screenshots.
So if I want to use the /.../ style, I select the code like this:
enter image description here

And if I want to use the // style, I select the code like this:
enter image description here

Timʘtei
  • 753
  • 1
  • 8
  • 21
  • Thanks... Wish multiline was phased out. – Alexander Jun 27 '18 at 15:00
  • @Alexander Why do you wish multiline was phased out? Commenting out the lines with the single comment notation is a pain in the butt to undo. It is also quicker to comment out large blocks. Multiline comments are also nice for inserting comments in between code (i.e. single line comments cannot do this). – Code Doggo Oct 24 '19 at 21:11
  • @DannyDan I mean phased out of IDE defaults; I find a lot more utility in single line comments and it's easy enough to add the 4 charcters without help from the IDE. – Alexander Oct 31 '19 at 17:11