Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 15 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: texts
 Post Posted: October 13th, 2017, 6:46 am 
 

Joined: September 24th, 2017, 3:23 am
Posts: 19
Hello, how do i display texts? Like during runtime i wanna display debug messages on screen?

also whats the difference between
Code:
 this;
to
Code:
 *this
? Arent they just the same since this returns the class? Thanks.


Top 
 Profile  
Reply with quote  
 Post subject: Re: texts
 Post Posted: October 13th, 2017, 7:11 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2853
Location: Oklahoma, United States
First, displaying text.
It depends...if you are using the chili framework and want to display text on screen like an overlay you can follow the Intermediate video on rendering text.
As for visual studio, you can send debug messages to the output window, though I don't remember the function name.

Second, this is a pointer pointing to the class it is apart of. *this dereferences the pointer. A pointer is just a variable to stores an address of some data. When you dereference the pointer, you are dealing with the data directly.

Syntax:
this->myData; the -> operator dereferences the pointer to access member data
(*this).myData; the * operator dereferences the pointer mostly used to pass a reference to an object, but using this syntax performs the same as the -> operator, dereference then access the data member.

Copying:
MyClass *pObject = this; this just copies the address stored at 'this'
MyClass &rObject = *this; this does the same except references can't be reassigned, so the 'rObject' can't point to anything else
MyClass vObject = *this; this actually makes a copy of the object that the this pointer points to.

EDIT: OutputDebugString( "This is a debut message sent to the output window" );
Found the function, here is the documentation if you want to look it over

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post subject: Re: texts
 Post Posted: October 15th, 2017, 12:44 pm 
 

Joined: September 24th, 2017, 3:23 am
Posts: 19
Hello albinopapa, thank you so much for the help. I don't understand pointers yet, I have got to that part of the tutorials.

Offtopic: My visual studio cannot run the framework anymore. I don't know what exactly happened but it's not running the chiliframework properly.


Top 
 Profile  
Reply with quote  
 Post subject: Re: texts
 Post Posted: October 15th, 2017, 1:49 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2853
Location: Oklahoma, United States
In what way will it not run properly?

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post subject: Re: texts
 Post Posted: October 15th, 2017, 1:59 pm 
 

Joined: September 24th, 2017, 3:23 am
Posts: 19
It runs normally in release but doesn't run on debug.

Edit: Nevermind bro, clean and build fixed the issue.


Top 
 Profile  
Reply with quote  
 Post subject: Re: texts
 Post Posted: October 18th, 2017, 11:06 pm 
 

Joined: September 24th, 2017, 3:23 am
Posts: 19
Hello, I have further questions regarding pointers. It seem easy to understand and I know I used it at some point in school (but that was turboC). I cant grasp the idea of getting strings via user input. I tried making my own functions and it can only get the first character right and the rest are some special characters. I can post my code later when i get home. Also isnt there a String class in C++ that can maybe make things easier to handle? Thanks in advance for the response.

Offtopic: should have named this thread as "Pointer Help or something"


Top 
 Profile  
Reply with quote  
 Post subject: Re: texts
 Post Posted: October 19th, 2017, 7:36 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2853
Location: Oklahoma, United States
How are you getting user input?

Yes, there is std::string and std::wstring if you #include <string>.

Code would help determine the issue.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post subject: Re: texts
 Post Posted: October 19th, 2017, 11:54 am 
 

Joined: September 24th, 2017, 3:23 am
Posts: 19
Hello albinopapa, heres my code.
Code:
void print(char* s, int size)
{
   for (char* p = s; p < s + size; p++)
   {
      _putch(*p);
   }
}

void scan(char* buf)
{
   for (char c = _getch(); _getch() != 13; buf++)
   {
      _putch(c);
   }
}

int main()
{
   
   print("Enter a number :", 18);
   char m[1000];
   char* msg = m;
   scan(msg);
   
   print("\nYou typed :", 15);
   print(msg, 100);


   while (!_kbhit())
   {
      ;
   }

    return 0;
}


I understand that this part works because its a loop that will terminate when enter is pressed. What I dont get is how it saves the values that the user is typing. Well, i cant get it to work right just like in the video tutorial. I hope you can help me understand what is going on.
Code:
void scan(char* buf)
{
   for (char c = _getch(); _getch() != 13; buf++)
   {
      _putch(c);
   }
}

I named it "scan" cause in turboC the function is called scanf.

I also have this other problem.
The code
Code:
while (!_kbhit())

does not prevent the console from closing. Hence, im using the do_nothing inside the loop.

Thank you in advance for the help.


Top 
 Profile  
Reply with quote  
 Post subject: Re: texts
 Post Posted: October 19th, 2017, 5:20 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2853
Location: Oklahoma, United States
Code:
void scan( char* buf )
{
   for( char c = _getch(); _getch() != 13; buf++ )
   {
      _putch( c );
   }
}

Take a look at this code from scan, where are you writing the input to the buffer?

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post subject: Re: texts
 Post Posted: October 19th, 2017, 5:30 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2853
Location: Oklahoma, United States
Empirean wrote:
I named it "scan" cause in turboC the function is called scanf.

Yeah, since C++ is compatible with C, functions like printf/fprintf/scanf/fscanf made their way into the C++ library also. With C++ you can use other utility functions and classes like std::string, std::stringstream, std::iostream and std::fstream. There are two global iostream objects for getting and setting user input to the console; std::cin and std::cout. Chili covers these a bit later in the tuts along with stringstream and fstream for strings and file access.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 15 posts ]  Go to page 1, 2  Next

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: