Reputation: 9
I dont understand what the 2nd adress in my program is`(readurl),
I found it out by cout'ing readurl(ifstream)
thank you for help/declarations! (The adress from readurl is'nt the same as cout'ing readurl)
Code:
#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();
}
The text file looks like this:
This will be readed
TEST
TEST
TEST
#This wont be readed
#This can be a comment.
#lsdjpofiuhpdsouhsdih+g
Upvotes: 0
Views: 181
Reputation: 409176
The expression &readurl
returns the address of where readurl
is in memory. The operator &
when used like this is called the address-of operator.
When you write out readurl
you are actually writing the actual object instance, and in this case it's not actually a valid output operation. You should have gotten warning about this when compiling, and the value you get from this can be anything.
The output from std::cout << readurl
is probably the same as the operator void*
override, and is not a valid address.
Upvotes: 1