我有一个字符数组 line=''hello world!''
使用什么函数判断字符串里是否有字母e?
如果有 ,返回1
或者自己编。怎么编呢?
第1个回答 2011-10-19
#include <string>
int main()
{
std::string line = "hello world";
size_t pos = line.find( "hello" );
if ( pos != std::string::npos )
{
//got it
}
return 0;
}
int main()
{
std::string line = "hello world";
size_t pos = line.find( "hello" );
if ( pos != std::string::npos )
{
//got it
}
return 0;
}
第2个回答 2011-10-19
#include <iostream>
using namespace std ;
int main ()
{
String line="hello world!";
int position = line.indexOf ( "e" ) ;
if ( position <= -1 )
{
//否
}
else
{
//有字母e , 返回1
}
}本回答被提问者采纳
using namespace std ;
int main ()
{
String line="hello world!";
int position = line.indexOf ( "e" ) ;
if ( position <= -1 )
{
//否
}
else
{
//有字母e , 返回1
}
}本回答被提问者采纳
第3个回答 2011-10-19
可以利用string类中的函数进行判断。或者利用循环将line看做一个数组进行遍历即可。