Please Help!: error: ‘endl’ is not a template function 360 | extern template ostream& endl(ostream&);

  c++, compiler-errors, endl, ostream, visual-studio-code

When I try to include <iostream> in my program I get an error:

In file included from c:mingwlibgccmingw32.2.0includec++ostream:702,
                 from c:mingwlibgccmingw32.2.0includec++iostream:39,
                 from .Centrealign1.cpp:1:
c:mingwlibgccmingw32.2.0includec++bitsostream.tcc:360:41: error: 'endl' is not a template function
  360 |   extern template ostream& endl(ostream&);
      |                                         ^
c:mingwlibgccmingw32.2.0includec++bitsostream.tcc:383:43: error: 'endl' is not a template function
  383 |   extern template wostream& endl(wostream&);
      |                                           ^

So I opened "ostream.tcc" and commented out two lines:

extern template ostream& endl(ostream&);
extern template wostream& endl(wostream&);

and then my program would work as I did not use endl in my program. However I can’t use endl anymore and the error comes back if I undo the comment.
I tried replacing contents of ostrem.tcc from a website, but the same error is shown.

The code I used is:

# include<iostream>

int main()
{   
    using namespace::std;
    int x=5;
    cout<<"Enter Required No. of rows:";
    cin>>x;
    x=(int)x+1;
    for(int j=x-1;j>0;j--)
    {

         for(int i=j;i>1;i--)
         {   
            cout<<" ";
         }
         for(int i=((x-j)*2)-1;i>0;i--)
         {
             cout<<"*";
         }
         cout<<"n";
    }
    
    return 0;
}

and… yes I am a beginner trying to do this in VSCODE. I would really appreciate any help.
Thank You in Advance ! 🙂

Source: Windows Questions C++

LEAVE A COMMENT