Wstring, wcin, wcout?

What do these mean? Before you say google.. everything I google comes up with the standard "cout" "cin" and "string" but not the wcout, wcin, or wstring.

I am looking through some random codes online for getting a processID of a program and came across one that declares variables of type wstring and also uses wcin with getline and wcout for console output.

is this a similar convention as with wchar(meaning wide string?) is this used for 64 bit systems?

Thanks for any help you can offer.
Ok, took me some time but I have an answer for you. The cin and cout are standard inputs and outputs but they can't handle wide characters. Wide characters are special characters generally used by another language, like Chinese characters which need more then 8 bits. A standard character is 8 bits. So when you cin, you are reading it in regards to 8 bits so you need something that will read characters as 16 bits instead, which is where wcin comes in.

You don't HAVE to use wcin, but it is better in regards to universality. Generally an english based windows won't ever have to worry about it though. Personally, I use cin since you can easily change code from char to WCHAR (I have a conversion.h that I wrote that automatically does this when I want to write code for UNICODE, I also have for my major headers

1
2
3
4
5
#ifndef _UNICODE
   hWnd = CreateWindow(chartoWCHAR(Title), chartoWCHAR(Title), .....
#else
   hWnd = Createwindow(Title, Title, .....
#endif 


As you can see here, this code was made to be used for UNICODE and non UNICODE which is generally what I write in. If you are more concerned with program size and are not going to worry about cross-language compatibility, then you should do the same as me and not use WCHAR or UNICODE. If you want to upgrade to support other languages, you must use UNICODE.

By the way, I assume most people post here already used google and either are confused with the responses they get or don't find what they need. This forum I believe (correct me if I am wrong) is tailored to getting a direct answer on C++ without all that hassle. Even though I haven't had to ask any questions here yet, I am always glad to help people where needed, tutoring or answering questions, in an effort to help people understand C/C++ better. So don't worry about the google response, you will never get it from me.

I may suggest reading up on certain topics to better understand them because sometimes the books can better explain something then me, but I will always direct you where you should go. Answering with google it to me is a waste of time because if no one answers then you would be forced to rely on google anyways which is not 100% guaranteed to help you.

The only reason I don't ask people to send me an e-mail with their questions is because those who are searching for answers can easily find answers here once they been answered. Now that your question is answered (to the best of my knowledge, someone may come along and better answer it after me), anyone who has the same question could learn from it much faster now that there is documentation on an answer and learn from it. I don't mind people messaging me for questions, but I like forums better because the help is more toward everyone rather then just one person.

Also, if someone told you to google it, most likely someone like me will tell them something they wouldn't want to hear and answer it for you anyways. I haven't been on this forum long but I have noticed there are quite a few people knowledgeable that seem to enjoy helping people. It is why I joined, also I too like hepling and guiding people. Are philosophies may not always agree but we share the same love for C\C++ and our desire to help people grow in the understanding of it.

As for your ProcessID, here is some code that may help that Mackabee posted

http://www.cplusplus.com/forum/windows/12137/

His code is great, but there is a cin version which I will put here but I wanted him having credit for his code because I based what I did on it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>
#include <windows.h>
using std::string;
using std::getline;
using std::cout;
using std::endl;

int main()
{
	string windowName;
	getline(std::cin, windowName);

	HWND windowHandle = FindWindowW(NULL, windowName.c_str());
	DWORD* processID = new DWORD;
	GetWindowThreadProcessId(windowHandle, processID);

	cout << "Process ID of " << windowName.c_str() << L" is: " << *processID << endl;

	system("PAUSE");
}


If you ran this code, it will also work unless you try to run it on Windows 7 Chinese version or some other language that has language characters that are too long for the standard char.
Last edited on
There is more to it than that. The standard wide streams (wcin, wcout, and wcerr) don't actually convert the wide characters you pass to them to anything sensible -- they only truncate the values to chars. See the narrow() function for all the disappointing details.

You are better off using the normal standard streams, and filtering yourself. (Unless you want to get deeper into codecvt facets and the like. Most people don't.)

Alas.
A standard character is 16 bits.


Usually 8.
Yeah, I realized that as soon as I clicked post and went back and changed it. I was hoping I fixed it before anyone realized my mistake. you caught me, LOL!
Thank you so much for the responses, I was using mackabee's code to get the PID.

If you happen to check this thread again, are you aware of any decent books on the WinAPI ? I am reading the MSDN (still not used to seeing DWORD, size_t, etc... it's a bit strange for me at the moment since i'm new to it) in conjuction with TheForger's API tutorial, but a lot of TheForger's code is not compiling properly, especially when I delve into resource creation. That.. and my editor does not allow me to edit resource files.. which also is a bummer. I am not so much interested in development solely for windows OS but there are a lot of things I wish to learn about the way things function on my favorite operating system!
Well, I personally went to bitlord and just downloaded every possible book I could find for C++ when I needed books. I still use books today when I need a refresher or when my brain decides to shut down because I am too involved into my code to see the obvious when I make mistakes.

Luckily C/C++ is cross-platform so you can generally code something on windows and use it on say Linux. there are some differences like Windows uses Winsock for internet applications where as Linux will not, but those differences are minimal. Windows will use system("PAUSE") to pause your program, Linux you need to use getchar() which also works in Windows sincei t just waits for a character to be pressed and since it doesn't dump it into a variable, continues without a second thought.

So the differences are minimal, so learning on any platform shouldn't hinder you too much when you want to use it on another later.

As for the books, I don't have any specific titles to recommend, I suggest using bitlord and downloading what you can. Some downloads will give you 200+ books in one shot so you can can choose which ones you like. Since everyone learns from different methods and different books teach different ways, this is probably the best way for you to find what is best for you.
Topic archived. No new replies allowed.