std::cout endl = weird results....
hi all i had a problem last week with regarding printing out a string and some other stuff and getting weird results. i thought my string allocation maybe was being messed up but through trial and error i realized it was the endl that i was giving my problems. i have never had this happen before so i hope you could possibly help me out...
whenever i invoke the endl such as a simple line of code:
std::cout << endl;
my output is: 004010EB
wha?????????
i am including <string> btw and like i said i havenever had this happen before. thanks for your time in advance :)
This is strange indead. You dont have to include <string> but <iostream>. Are you using namespace std ?? Make sure endl is not declared as a pointer of some kind or variable.
nevermind i figured it out..why is it when i post on here half the time about 5 minutes later i figure it out while spending more than enough time before ive written the post?
anyway i have multiple classes together and inheritance going on. even though i included the <string> header file and the <iostream> header file in the .cpp file i didnt do the following line of code:
using namespace std;
even though i had done it with parent class it still was giving me this garbage in the child class.
ok ive got it fixed but why was i getting this output? just wanna know deeper of the problem.. thanks!
anyway i have multiple classes together and inheritance going on. even though i included the <string> header file and the <iostream> header file in the .cpp file i didnt do the following line of code:
using namespace std;
even though i had done it with parent class it still was giving me this garbage in the child class.
ok ive got it fixed but why was i getting this output? just wanna know deeper of the problem.. thanks!
well i was including <iostream> and <string> because of strcpy() that i needed.. but as i just wrote (as you were writing :D) i explained the problem but would like to know further why i was getting the output because of the line of code i didnt implement... thanks again.
Most likely the endl was resolving to a symbol other than std::endl that had an implicit conversion to void *. If you use operator<< on a std::ostream with a void *, it prints the address of the pointer.
thanks mod.. like i said this has never happpened before and i have an unusual multiple inheritance going on such as
class a : protected class b, private class c
{...}
i simply forgot to add the using namespace std in one of my .cpp files ...so i guess i wont ever forget that again.. or at least when i get that error i will know what i need to change...
class a : protected class b, private class c
{...}
i simply forgot to add the using namespace std in one of my .cpp files ...so i guess i wont ever forget that again.. or at least when i get that error i will know what i need to change...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement