0

我不明白我程序中的第二个地址是什么`(readurl),我通过 cout'ing readurl(ifstream) 找到了它,谢谢你的帮助/声明!(来自 readurl 的地址与 cout'ing readurl 不同)
代码:

#include <fstream>
#include <iostream>
#include <string>
#include <tchar.h>
using namespace std;
int main()
{
    string file; //filepath
    int sel; //menu-switch
    cout << "Select your Language!"<<endl;
    cout << "1:German"<<endl;
    cout << "2:English"<<endl;
    cout << "Language: ";
    cin  >> sel;
    getchar();
    system("cls");
    switch(sel)
    {
        case 2:
            cout << "Hello!"<<endl;
            cout << "Select your File: ";
            cin  >> file;
            getchar();
            system("cls");
            break;
        case 1:
            cout << "Hallo!"<<endl;
            cout << "Waehle deine Datei aus: ";
            cin  >> file;
            getchar();
            system("cls");
    }
    ifstream readurl(file.c_str());
    char url[CHAR_MAX];
    while(!readurl.getline(url,CHAR_MAX,'#'))
    {
        readurl.ignore();
    }
    cout << endl;
    cout << &readurl<<endl<<readurl<<endl; // What is readurl?
    cout << "File: (Sentences with # will be ignored)"<<endl;
    cout << url;
    getchar();
}

文本文件如下所示:

This will be readed
TEST
TEST
TEST
#This wont be readed 
#This can be a comment.
#lsdjpofiuhpdsouhsdih+g
4

1 回答 1

1

表达式&readurl返回readurl内存中 where 的地址。像这样使用的运算符&称为地址运算符。

当您写出时,readurl您实际上是在编写实际的对象实例,在这种情况下,它实际上不是有效的输出操作。你应该在编译时得到警告,你从中得到的值可以是任何东西。


from 的输出std::cout << readurl可能与operator void*覆盖相同,并且不是有效地址。

于 2013-01-12T20:06:37.230 回答