C++ 指向类的指针上的位运算符?

C++ 指向类的指针上的位运算符?,c++,bit-manipulation,ifstream,readfile,C++,Bit Manipulation,Ifstream,Readfile,我花了一天的时间挖掘项目中前一个家伙的遗留代码,而且我还搜索了关于位运算符的内容,我仍然无法清楚地理解位运算符的代码行: input >> *graph; 我可以编译和运行,但是,我放了2个printf函数供您参考:它可以打印“11111”和之后的“4”,但永远不能打印“2222”,所以按位运算符行一定有问题。我怎样才能解决这个问题 *graph是指向GGraph类对象的指针: class GGraph{ public: GGraph(); ~GGraph(); void add

我花了一天的时间挖掘项目中前一个家伙的遗留代码,而且我还搜索了关于位运算符的内容,我仍然无法清楚地理解位运算符的代码行:

input >> *graph;
我可以编译和运行,但是,我放了2个printf函数供您参考:它可以打印“11111”和之后的“4”,但永远不能打印“2222”,所以按位运算符行一定有问题。我怎样才能解决这个问题

*graph
是指向GGraph类对象的指针:

class GGraph{
public:
GGraph();

~GGraph();
void addNode ( GNodeData nodedata, GNodeOrGroup orgroup = GNOGROUP );
void delNode (); //code...........
};
仅供参考:这是程序的一部分,用于返回图形数据集中的频繁模式(图形挖掘)。我在这里询问的代码块只是从文件中打开和读取图形数据信息的过程。图形数据如下所示:

t # 0
v 0 0
v 1 0
...
(all the vertices with their labels)
e 0 1 3
e 1 2 3
...
(all the edges with the vetices they connect and their labels)
t # 1 (graph No.2)
....
这是程序在运行时无法传递的代码块:

void GDatabase::read ( string filename )
    {
        char header[100];
        ifstream input ( filename.c_str () );
        GGraph *graph = new GGraph ();

        input.getline ( header, 100 ); // we assume a header before each graph
        printf("%s", header);

    //    char c;
    //    c = input.get();
    //    while (input) {
    //        std::cout << c;
    //        c = input.get();}

        getchar();
        printf("11111111111");
        printf("\n%d",sizeof(graph));

        input >> *graph;
        printf("2222222222");
        while ( !input.eof () ) {
            process ( graph );
            graphs.push_back ( graph );
            graph = new GGraph ();
            input.getline ( header, 100 );
            input >> *graph;
        }
        delete graph;     
        input.close ();
    }
输入>>*图形

这不是按位运算符。它是一个流提取操作符。在代码中的某个地方,必须定义一个
操作符>
,该操作符将流和GGraph作为输入,例如:

template<class CharT, class Traits = std::char_traits<CharT> >
std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits> &in, GGraph &graph)
{
    // read values from in and store them in graph as needed...
    return in;
}
他实际上是在打电话:

operator>>(input, *graph);

该按位运算符实际上可能是一个流提取运算符。你能在代码中的某个地方搜索
operator>
吗?注释部分是我添加的用来检查ifstream输入是否有任何内容的部分,它会打印出文件的所有内容。但是,如果我运行这部分代码,图形数据文件中就没有任何内容可供程序继续处理了……在从
ifstream
读取一次之后,您必须将其查找回文件的开头,以便再次读取。此提取器函数完全占用了eof的处理(如果流具有eof以外的错误条件,则将进入无限循环)@mattmcnab是的,我认为罪魁祸首是:do{m=stream.get();}而(m!='\n');我一步一步地调试。它永远不会得到新行“\n”从流中,它确实陷入了无限循环。如何从流中获取新行字符?谢谢,是的,我找到了两行,也许这就是你的意思:istream&operator>>(istream&stream,GGraph&graph);ostream&operator在这里。那么实际的问题是什么呢?实际上这是一个位运算符,它被一个完全不相关的语义重载了,只是因为它看起来很时髦,而且具有相当高的优先级。@RemyLebeau我对问题中的运算符定义的细节进行了编辑。问题是我无法通过流读取过程…:)
input >> *graph;
operator>>(input, *graph);