texts

The Partridge Family were neither partridges nor a family. Discuss.
Empirean
Posts: 26
Joined: September 24th, 2017, 3:23 am

texts

Post by Empirean » October 13th, 2017, 6:46 am

Hello, how do i display texts? Like during runtime i wanna display debug messages on screen?

also whats the difference between

Code: Select all

 this; 
to

Code: Select all

 *this 
? Arent they just the same since this returns the class? Thanks.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: texts

Post by albinopapa » October 13th, 2017, 7:11 am

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

Empirean
Posts: 26
Joined: September 24th, 2017, 3:23 am

Re: texts

Post by Empirean » October 15th, 2017, 12:44 pm

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.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: texts

Post by albinopapa » October 15th, 2017, 1:49 pm

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

Empirean
Posts: 26
Joined: September 24th, 2017, 3:23 am

Re: texts

Post by Empirean » October 15th, 2017, 1:59 pm

It runs normally in release but doesn't run on debug.

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

Empirean
Posts: 26
Joined: September 24th, 2017, 3:23 am

Re: texts

Post by Empirean » October 18th, 2017, 11:06 pm

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"

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: texts

Post by albinopapa » October 19th, 2017, 7:36 am

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

Empirean
Posts: 26
Joined: September 24th, 2017, 3:23 am

Re: texts

Post by Empirean » October 19th, 2017, 11:54 am

Hello albinopapa, heres my code.

Code: Select all

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: Select all

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: Select all

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.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: texts

Post by albinopapa » October 19th, 2017, 5:20 pm

Code: Select all

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

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: texts

Post by albinopapa » October 19th, 2017, 5:30 pm

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

Post Reply