我知道strchr在<string>。但是uva10082给了CE:
code.cpp: In function ‘int main()’:
code.cpp:6:13: warning: unknown escape sequence: '\A'
char x[] = "`1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./"; ^
code.cpp:11:24: error: ‘strchr’ was not declared in this scope
p = strchr(x, char(c));下面是我的代码:(使用c++11编译)
#include<iostream>
#include<string>
using namespace std;
int main()
{
char x[] = "`1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./";
int c;
char* p = NULL;
while ((c = getchar()) != EOF)
{
p =strchr(x,char(c));
if (p)
cout << *(p-1);
else
cout << char(c);
}
}发布于 2014-08-07 09:09:15
#include <cstring> // contains strchr而且,没有必要将第二个参数转换为char,因为strchr在那里使用int
发布于 2014-08-07 09:09:31
你需要
#include<cstring>拥有strchr()。另外,对于getchar()和EOF,您需要
#include<cstdio>注意,<string>库包含例如std::string类,而<cstring>包含C字符串函数,如strchr()、strcat()等等。
因此,您关于strchr()在<string>库中的声明是不正确的。
发布于 2014-08-07 09:08:36
我猜std::strchr在#include <cstring>
https://stackoverflow.com/questions/25178409
复制相似问题