unicode文本文件 [英] unicode text file

查看:106
本文介绍了unicode文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些unicode(utf8)文本文件。我_tried_写了一个简单的

程序,读取其中一个并将其写入标准输出但是......

当然它不起作用。有一个简单的方法吗?谢谢,K。


这是我的计划。


#include< fstream>

#include< ; iostream>

#include< string>


using namespace std;


int main(){

ifstream infile(" in.txt");

string s;

while(infile>> s){

cout<< s;

}

}

I have some unicode (utf8) text file. I _tried_ to write a simple
program that read one of them and write it to the standard output but...
of course it doesn''t work. There is an easy way to do it? Thanks, K.

This is my program.

#include <fstream>
#include <iostream>
#include <string>

using namespace std;

int main(){
ifstream infile ("in.txt");
string s;
while (infile >> s) {
cout << s;
}
}

推荐答案



" ; Koulbak" <涂******** @ gmail.com>在消息中写道

news:42 ********** @ news.bluewin.ch ...

"Koulbak" <tu********@gmail.com> wrote in message
news:42**********@news.bluewin.ch...
我有一些unicode(utf8)文本文件。我_tried_写了一个简单的程序
读取其中一个并将其写入标准输出但是......当然
它不起作用。有一个简单的方法吗?谢谢,K。

这是我的程序。

#include< fstream>
#include< iostream>
#include< string> ;

使用命名空间std;

int main(){
ifstream infile(" in.txt");


您应该在尝试阅读之前检查文件是否已成功打开



string s;
while(infile>> s){
cout<< s;
}
}
I have some unicode (utf8) text file. I _tried_ to write a simple program
that read one of them and write it to the standard output but... of course
it doesn''t work. There is an easy way to do it? Thanks, K.

This is my program.

#include <fstream>
#include <iostream>
#include <string>

using namespace std;

int main(){
ifstream infile ("in.txt");
You should here check that file was opened successfully
before attempting to read from it.
string s;
while (infile >> s) {
cout << s;
}
}




尝试使用''wifstream''和''wcout''。


-Mike



Try using ''wifstream'' and ''wcout''.

-Mike


Mike Wahler写道:

[读取unicode文本文件]
Mike Wahler wrote:
[read unicode text file]
int main(){
ifstream infile(" in.txt");
int main(){
ifstream infile ("in.txt");



您应该检查该文件是否已成功打开
在尝试阅读它之前。



You should here check that file was opened successfully
before attempting to read from it.




在真正的程序中我当然是这样做的,但在我的帖子里我只放了

必不可少的部分问题。



In the real program of course I do it, but in my post I put only the
essential part of the question.

string s;
while(infile>> s){
cout<< ; s;
}
}
string s;
while (infile >> s) {
cout << s;
}
}



尝试使用''wifstream''和''wcout''。


Try using ''wifstream'' and ''wcout''.




1试过,它没有编译。


错误C2679:二进制''>>'':找不到右侧的运算符

类型''std :: string''的操作数(或者没有可接受的转换)


我还添加了wstring并且它编译但是它确实没有工作正常:它

会打印大量垃圾。


2我认为使用C ++可以完全使用

标准方式(避免特殊构造为wcout)可能设置一些

库选项。是不是真的?


非常感谢,K。



1 Tried, it doesn''t compile.

error C2679: binary ''>>'' : no operator found which takes a right-hand
operand of type ''std::string'' (or there is no acceptable conversion)

I added also wstring and it compile but it doens''t work correctly: it
prints a lot of garbage.

2 I thought that with C++ there was the possibility to use exactly the
standard way (avoid special construct as wcout) maybe setting some
library option. Is it not at all true?

Thanks a lot, K.


Koulbak写道:
Koulbak wrote:
1试过,它没有编译。

错误C2679:二进制''>>'':找不到哪个操作符带右手
操作数类型''std :: string''(或者没有可接受的转换)



你应该使用wstring。 wchar_t字符串文字以L为前缀。例如:

wstring s = L" Some string" ;;

我还添加了wstring并且编译但是它确实没有工作正常:它打印了大量的垃圾。

2我认为用C ++可以完全使用
标准方式(避免使用特殊构造作为wcout)设置一些库选项。是不是真的?
1 Tried, it doesn''t compile.

error C2679: binary ''>>'' : no operator found which takes a right-hand
operand of type ''std::string'' (or there is no acceptable conversion)

You should use wstring. A wchar_t string literal is prefixed with L. For example:
wstring s= L"Some string";
I added also wstring and it compile but it doens''t work correctly: it
prints a lot of garbage.

2 I thought that with C++ there was the possibility to use exactly the
standard way (avoid special construct as wcout) maybe setting some
library option. Is it not at all true?




这些*是*标准设施。所有的字符串工具都带有他们的wchar_t等价物

(包括C子集的设施)。


-

Ioannis Vranos

http://www23.brinkster.com/noicys


这篇关于unicode文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆