我有一个包含任何字符的输入,并且我需要有一个数组来分隔输入中的单词。该数组只需要包含字母(是西班牙语,所以它包含重音字母)。我的代码做到了,它只是不能识别特殊的西班牙语字符,如“”、“?”等。
我怎样才能改正这个错误呢?这是我的代码。
string x[100];
int n = 0;
while (entrada){
entrada>>x[n];
n++;
}
n--;
for(int j = 0;j<n;j++){
cout<<x[j]<<"/";
}
string y[100];
for(int i = 0;i<n;i++)
for(int j = 0; j<x[i].length();j++){
if(!ispunct(x[i][j]))
y[i]+=x[i][j];
}使用下面的代码,我得到了以下输入和输出:
input
=======
Hola,
Cómo estás?
Espero que muy bien. ¡!!!
El otro día que fui al cine me acordé de la
película que vimos el año pasado.
output
========
Hola/Cómo/estás/Espero/que/muy/bien/¡/El/otro/día/que/fui/al/cine/me/acordé/de/la/película/que/vimos/el/año/pasado/输出只是打印出来的数组,中间用"/“分隔
发布于 2013-02-19 08:45:28
尝试设置区域设置,如下所示:
#include <clocale>
...
std::setlocale(LC_ALL, "es_ES");它应该能让ispunct()识别西班牙语标点符号。
https://stackoverflow.com/questions/14947791
复制相似问题