6 Replies - 3743 Views - Last Post: 17 April 2009 - 03:35 AM Rate Topic: -----

#1 dhanaid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-April 09

Displaying Chinese Characters in c++

Posted 14 April 2009 - 06:41 AM

hai all,
I am new to c++. I want to display Chinese Pinyin Characters.
That is when i type keys in en_us/ de key board, it will display corresponding Chinese Pinyin Characters.

Thanks in advance
Is This A Good Question/Topic? 0
  • +

Replies To: Displaying Chinese Characters in c++

#2 trixt.er  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 52
  • View blog
  • Posts: 426
  • Joined: 28-September 08

Re: Displaying Chinese Characters in c++

Posted 14 April 2009 - 07:00 AM

Dreamincode has a policy that requires you to post some code before recieving assistance. Let us know how your question relates to C++ programming. If not then go to a different forum.
Was This Post Helpful? 0
  • +
  • -

#3 dhanaid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-April 09

Re: Displaying Chinese Characters in c++

Posted 16 April 2009 - 06:44 AM

I have used the following to read UTF-8 encoded text file which consists of Chinese PinYin Characters.

#include "iostream"
#include "string"
#include "stdio.h"
#include "fstream"
using namespace std;

int main(int argc)
{
std::string _name;  

wchar_t ch;
  
	wifstream infile;
 
	wfilebuf * inbuf;
 
	infile.open("D:\\chinesepinyins.txt");
 
	inbuf = infile.rdbuf();
 
	ch = inbuf->sgetc();
  
	while(ch !=0xffff)
	{
		wcout.put(ch);
	  
		ch = inbuf->snextc();
 
	}
 
	infile.close();
 
	 system("pause");
	
	return 0;
}




This code will read the text file and display some string in command prompt.
not the exact Characters. I have no idea whether command window will display chinese characters.

My issue is when i gave input like "ai" from command window, it will read the correndponding values from text file and display the characters.

Thanks in advance

Attached File(s)


This post has been edited by dhanaid: 17 April 2009 - 01:55 AM

Was This Post Helpful? 0
  • +
  • -

#4 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Displaying Chinese Characters in c++

Posted 16 April 2009 - 07:01 AM

Please note posting rule 4 and
:code:
Was This Post Helpful? 0
  • +
  • -

#5 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Displaying Chinese Characters in c++

Posted 16 April 2009 - 07:11 AM

Well you wonder if your console will display characters.
When faced with a problem break it down into small parts and solve each little chunk.

Let's conduct a little experiment.

Compile and run this little program

#include <iostream>
#include <string>

using namespace std;

int main() {
    string a = "阿啊吖嗄锕安爱暗案按";
    cout << a << endl;
    return 0;
}



What happened?

This post has been edited by janotte: 16 April 2009 - 07:14 AM

Was This Post Helpful? 0
  • +
  • -

#6 dhanaid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-April 09

Re: Displaying Chinese Characters in c++

Posted 17 April 2009 - 12:18 AM

View Postjanotte, on 16 Apr, 2009 - 06:11 AM, said:

Well you wonder if your console will display characters.
When faced with a problem break it down into small parts and solve each little chunk.

Let's conduct a little experiment.

Compile and run this little program

#include <iostream>
#include <string>

using namespace std;

int main() {
    string a = "阿啊吖嗄锕安爱暗案按";
    cout << a << endl;
    return 0;
}



What happened?




hi

it will display ????????????? .
so i tried with UTF-8 encoded text file...
displays some thing but not exact ones.
Was This Post Helpful? 0
  • +
  • -

#7 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Displaying Chinese Characters in c++

Posted 17 April 2009 - 03:35 AM

Have you got new code or are you still using the code above?

If you have new code please share it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1