为什么我的程序说长度函数不在我的标准库中?

Why is my program saying that the length function is not in my std library?

我的程序说函数 length() 不在标准库中并且产生了一个错误,该错误不允许我 运行 我的代码

我尝试将两个不同的库放入#include 语句中。然后我尝试将长度函数放在不同的变量上,但发生了同样的错误。

int main()
{
    string line;
    ifstream out_file_DOI("declaration_of_independence.txt");
    if (out_file_DOI.is_open())
    {
        int i = 0;
        while (getline(cout, out_file_DOI, i))
        {
            cout << line << endl;
            cout << line.length();   //error is on this line...
            i++;
        }
        out_file_DOI.close();
      }
    }
    else
    {
        cout << "Unable to open file...";
    }
    //creates the declaration file
    out_file_DOI.open("declaration_of_independence.txt");
  }

我希望代码 运行 并显示正确的结果(正确的结果是加密文件的程序(独立宣言)。

如果你想从文件中逐行读取到“line”字符串,

getline(out_file_DOI, line);