- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个名为aisha的文本文件
This is a new file I did it for mediu.
Its about Removing stopwords fRom the file
and apply casefolding to it
I Tried doing that many Times
and finally now I could do
然后我编写了一个代码来读取该文本文件并将其保存到一个数组中,然后将一些字符转换为小写字母但我想要的是让代码将文件读取为字符串而不是 char
char myArray[200];
成为
`string myArray[200];`
我想我可以使用函数 tolower()
和一个字符串 std输入我使用的长代码但我不知道如何将我的代码更改为使用该功能的代码
我的代码是
#include <iostream>
#include <string>
#include <fstream>
#include<ctype.h>
int main()
{
using namespace std;
ifstream file("aisha.txt");
if(file.is_open())
{
file >> std::noskipws;
char myArray[200];
for(int i = 0; i < 200; ++i)
{
cout<<"i";
if (myArray[i]=='A')
cout<<"a";
if (myArray[i]=='T')
cout<<"t";
if (myArray[i]=='R')
cout<<"r";
else
if (myArray[i]!='I' && myArray[i]!='T' && myArray[i]!='R'&& myArray[i]!='A')
cout<<myArray[i];
}
file.close();
}
system("PAUSE");
return 0;
}
我在这个网站上看到了那个解决方案但我无法将它应用到我的代码中
#include <boost/algorithm/string.hpp>
std::string str = "wHatEver";
boost::to_lower(str);
Otherwise, you may use std::transform:
std::string str = "wHatEver";
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
最佳答案
以下代码可以解决您的问题:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cctype>
#include <algorithm>
#include <iterator>
using namespace std;
int main(int argc, char **argv) {
ifstream ifs("file");
ostringstream oss;
char c;
while(true) {
c = ifs.get();
if(ifs.good())
oss.put(c);
else
break;
}
string s = oss.str();
transform(s.begin(), s.end(), ostream_iterator<char>(cout), ::tolower);
return 0;
}
关于c++ - 在 C++ 中使用 tolower() 函数将字符串转换为小写字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20309887/
我想在 Perl 中用另一个替换一个字符串;两者长度相同。我想替换所有出现的字符串(不区分大小写),但我希望保留字母的大小写。所以如果第一个字母是大写的,替换后的第一个字母也将是大写的。 例如,如果我
如何更改以下 .htaccess 文件片段以实现: 现在如果它重写,它需要用户从: domain.com/TEST - domain.com/test domain.com/subdir/TEST -
我想将'abcdef'转换为'aBCdeF'或'AbCDEF'或任何其他大小写字符的随机组合。我需要将其与任何给定的字符串一起使用。我知道String的#upcase,#swapcase,#capit
我正在检查对象是否与默认值匹配,但我不关心大小写差异。 当前功能: function checkSingleDifference(property) { if ($scope.defaults
我有一个 python 字典,如下所示 my_dict = {u'customer': [u'GS808E', u'GS810EMX'], u'tablets': [u'Apple IPAD PRO'
如果我在 Testcafe 脚本中使用函数“WithText”,看起来它取决于小写和大写书写。我怎样才能让它独立?所以接受用户“我的名字”和“我的名字”?如果出现翻译问题,脚本将失败是很糟糕的。 最佳
我有一个 HTML 文本元素,例如:一个名为 VIDEOS 的 H1 标签。有什么办法可以用JS随机操作文字的大小写吗?因此,例如,在一个实例中,它将文本加载为 viDEoS,在另一个实例中,它加载了
我需要创建一个函数来读取字符串输入并将字符串中的奇数索引字符转换为大写,偶数索引字符转换为小写。 function alternativeCase(string){ for(var i = 0
代码如下: def upper_every_nth (s, n): i = 0 while len (s) > (i * (0 + n)) : character =
有点奇怪的要求,我知道。但是我一直在寻找解决这个问题的方法已经有一段时间了。这是我正在寻找的效果: var myString = "Hello I am randomly capitalized" 期
所以,我想做的是创建一个将大写字符切换为小写字符的函数,反之亦然。 这是我正在使用的: #include #include int caplowswitch(char string[], char
我有一个 json 文件,我正在寻找一个值的小写部分 - 我可以 jq 值和小写字符串,但我如何确保这个新的小写值被添加回整个文件? jq '.[].Id' file.json | awk '{pri
有没有办法在 Racket 中将字符串中的所有字符都变成小写? 我能想到的唯一方法是将字符转为小写,但它不适用于字符串 我使用的是初学者语言,所以我无法使用某些功能 最佳答案 在实践中,你会使用 st
我需要将相同的变量转换为大写|小写|大写。 /** * @package ${1 default="Hello"} * @subpackage ${com}_${1 capitalize
现场电子邮件: 可以在 Nativescript 上的 RadDataForm 中设置 autocapitalizationType="none"吗? 最佳答案 截至今
我在Scala中发现了一个很奇怪的问题。我试图获取上个月的最后一天。下面的工作表显示了正确的结果(在 Scala 中,月份从 0(一月)开始,所以三月是 2)。 但是,如果我注释掉左边最后一行,结果如
我有关于在 JTextField 中输入的问题。我的程序搜索几个 csv 文件并查找 JTextField 字符串中指定的内容。我已添加 readLine 函数“.toLowerCase”以将所有字符
通过使用一个输入文本框,输入类型只允许字母。输入的值为'a',它应该在文本框外显示为'A'? 如果我们在输入文本中输入小写字母“a”,那么它会希望在框外显示大写字母“A”...以下是我的html代码:
我正在开发一个特殊的脚本来修复文本区域内的字母。我在堆叠时发现了一个问题。在 Stackoverflow 上,我找不到解决方案,需要帮助。 我的脚本有一个系统,用于识别每个以大写首字母开头的单词,以及
我有两个文本字段:1 个文本字段值来自使用 ahax 的数据库: $("#p_plus_h").val(moment().add('days', prod.p_plus).format("DD MMM
我是一名优秀的程序员,十分优秀!