鉴于代码:
#include <iostream>
#include <cctype>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string s("ABCDEFGHIJKL");
transform(s.begin(),s.end(),s.begin(),tolower);
cout<<s<<endl;
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
呼叫没有匹配功能
transform(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, <unresolved overloaded function type>)
什么是"未解决重载函数类型"是什么意思?
如果我用tolower我写的函数替换它,它不再是错误.
我在Ubuntu g ++版本4.4.3中编译的c ++问题中遇到此问题.我不知道要包含的标题来解决这个问题..谢谢
centro_medico.cpp: In constructor ‘Centro_medico::Centro_medico(char*, char*, int, int, float)’:
centro_medico.cpp:5: error: ‘strcpy’ was not declared in this scope
centro_medico.cpp:13: warning: deprecated conversion from string constant to ‘char*’
centro_medico.cpp:13: warning: deprecated conversion from string constant to ‘char*’
centro_medico.cpp: In member function ‘Centro_medico& Centro_medico::operator=(const Centro_medico&)’:
centro_medico.cpp:26: error: ‘strcpy’ was not declared in this scope
centro_medico.cpp:39: warning: deprecated conversion from string constant to ‘char*’
centro_medico.cpp:39: warning: deprecated conversion from string constant to ‘char*’
centro_medico.cpp: In member function ‘bool Centro_medico::quitar_medico(int)’:
centro_medico.cpp:92: …Run Code Online (Sandbox Code Playgroud) 我需要对以下c ++语法进行一些解释:
for(const auto& ioDev : deviceList)
Run Code Online (Sandbox Code Playgroud)
鉴于:
std::vector<Device *> deviceList
Run Code Online (Sandbox Code Playgroud)
具体来说,我对':'和'auto'的使用感到困惑?
我在几个地方读到过boost :: algorithm :: to_upper/to_lower对utf8不好:
但是在我的系统上,ubuntu 12.4.1 32位,增强1.46,以及locale en_GB.UTF-8,一切看起来都很好,只要我通过语言环境例如:
std::locale englishUTF8locale("en_GB.UTF-8")
boost::algorithm::to_upper_copy(L"ü", englishUTF8locale) -> L"Ü"
boost::algorithm::to_lower_copy(L"?", englishUTF8locale) ->L"?"
Run Code Online (Sandbox Code Playgroud)
值得注意的是,它在使用std :: wstring时有效,但在使用std :: string时则无效
那么,boost :: locale是不是真的有必要?我的问题是我只能使用boost 1.46,而locale是为1.48创建的
我正在尝试将字符串转换为小写,并将其视为char*并迭代每个索引.问题是tolower我在网上读到的函数实际上并没有将char转换为小写:它将char作为输入并返回一个整数.
cout << tolower('T') << endl;
Run Code Online (Sandbox Code Playgroud)
116应该打印时打印到控制台T.
有没有更好的方法将字符串转换为小写?我在网上看过,大多数消息来源都说"使用tolower并遍历char数组",这对我来说似乎并不适用.
所以我的两个问题是:
tolower当我打电话时,它使得它返回116而不是't' 的功能我做错了什么tolower('T')
除了tolower在每个单独的字符上使用之外,还有更好的方法将字符串转换为C++中的小写字母吗?
让我们假设我想编写自己的输入和输出操纵器.
cin >> mymanip >> str;
Run Code Online (Sandbox Code Playgroud)
要么
cout << mymanip << str;
Run Code Online (Sandbox Code Playgroud)
我希望mymanip做的是切换我从输入中读取的字符并将结果分配给一个字符串.
所以,如果我输入"QwErTy",我会在字符串中输入"qWeRtY".
这是一个非常基本的任务,只有一个功能,但我想了解更多关于操纵器的知识.
有人能给出一个线索吗?
谢谢.
我的工作是编写一个程序,将句子转换为大写和小写.
#include <iostream>
using namespace std;
int main ()
{
int current;
string sent;
cout << "Please enter a sentence: ";
cin >> sent;
for (int i = 0; i < sent.length(); i++)
{
current = (int) sent[i];
cout << "Your sentence in all lower case: "<< sent;
cout << endl;
if (current >= 65 && current <= 90)
{
current += 32;
sent[i] = (char) current;
cout << "Your sentence in all upper case: " << sent;
}
} …Run Code Online (Sandbox Code Playgroud) 为简单起见,我选择使用类型“字符串”而不是“字符”。但我应该小写我从输入文件中读入的字符串。我当时不知道我将无法使用“tolower()”。但是我确实找到了一种使用“转换”的方法。但是我无法让它工作,也找不到将它与一系列结构一起使用的示例。请帮忙。如果可能的话,我还必须将每个州的第一个字母大写,因此如果您能指出正确的方向,将不胜感激。
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <algorithm>
struct ATdata
{
string state;
double miles;
int shelters;
};
int readData( ifstream& input, struct ATdata data[] );
size_t readData( ifstream& input, struct ATdata data[], size_t MAX_ENTRIES );
int main()
{
ifstream input;
char filename[256];
ATdata data[14];
int i;
cout << "Enter input file name: ";
cin >> filename;
input.open( filename );
if ( input.fail() )
{
cout << "Input file does not exist." << endl;
exit(1);
}
size_t …Run Code Online (Sandbox Code Playgroud) 我创建了自定义函数将wstring转换为小写.但是,它在DebugMode中相当慢.是的,我知道ReleaseMode是重要的,但无论如何它是非常令人不安的.
wstring wstringToLower(wstring u)
{
wstring s;
for (int i=0;i<u.size();i++)
{
wstring sChar;
sChar=u.substr(i,1);
int iChar=static_cast<int>(sChar[0]);
int iNewChar=charCodeToLower(iChar);
wstring sNewChar=wstring(1,iNewChar);
s.append(sNewChar);
}
return s;
}
Run Code Online (Sandbox Code Playgroud)
有没有人看到任何明显可以改进以加速代码的东西,即使在DebugMode中也是如此?
谢谢!
c++ ×10
string ×3
lowercase ×2
tolower ×2
boost ×1
c++11 ×1
char ×1
character ×1
deprecated ×1
for-loop ×1
loops ×1
manipulators ×1
optimization ×1
performance ×1
toupper ×1