นี่คือรหัสตัวอย่างของฉัน:
#include <iostream>
#include <string>
using namespace std;
class MyClass
{
    string figName;
public:
    MyClass(const string& s)
    {
        figName = s;
    }
    const string& getName() const
    {
        return figName;
    }
};
ostream& operator<<(ostream& ausgabe, const MyClass& f)
{
    ausgabe << f.getName();
    return ausgabe;
}
int main()
{
    MyClass f1("Hello");
    cout << f1;
    return 0;
}ถ้าผมแสดงความคิดเห็นออก#include <string>ฉันไม่ได้รับรวบรวมข้อผิดพลาดใด ๆ #include <iostream>ผมคิดว่าเพราะมันเป็นชนิดของการรวมผ่าน ถ้าฉัน"คลิกขวา -> ไปที่คำจำกัดความ"ใน Microsoft VS ทั้งคู่ชี้ไปที่บรรทัดเดียวกันในxstringไฟล์:
typedef basic_string<char, char_traits<char>, allocator<char> >
    string;แต่เมื่อฉันเรียกใช้โปรแกรมฉันได้รับข้อผิดพลาดข้อยกเว้น:
0x77846B6E (ntdll.dll) ใน OperatorString.exe: 0xC00000FD: Stack overflow (พารามิเตอร์: 0x00000001, 0x01202FC4)
ความคิดว่าทำไมฉันจะได้รับข้อผิดพลาด runtime เมื่อแสดงความคิดเห็นออกมา#include <string>? ฉันใช้ VS 2013 Express
#include<iostream>และทั้งสองอาจจะรวมถึง<string> <common/stringimpl.h>
                ...\main.cpp(23) : warning C4717: 'operator<<': recursive on all control paths, function will cause runtime stack overflowเมื่อเรียกใช้บรรทัดนี้cl /EHsc main.cpp /Fetest.exe