注册 登录
编程论坛 C++教室

数据结构字符串find函数综合应用问题

孤魂居士 发布于 2007-11-09 18:49, 1444 次点击
各位大哥 今天我们刚刚上到这里 下面这个程序就是今天上机的内容 怎么还是有个错误呢``不知道怎么回事``
兄弟们 帮我喵描




#include<iostream.h>
#include<string.h>
//using namespace std; 这句用.h就不能用
string str="mississ ippi";
void main()
{
int index;
index=str.find_first_of('s',0); //找字符C的位置,从0位置开始找
cout<<index<<endl;
index=str.find_first_of('s',4) //找字符s位置,从第4个位置开始找起
cout<<index<<endl;
index=0;
while((index=str.find_first_of('i',index))!=-1) //这里掉了一对括号
{
cout<<"index:"<<index<<" "<<endl;index++;
}
index=str.find_last_of(' ');
string firstname,lastname; //firstname中间没有空格
firstname=str.substr(0,index);
lastname=str.substr(index=+1,-1)
index=str.find("miss");
cout<<index<<endl;
index=str.find("ippi");
index=str.find("ippi",8);
cout<<index<<endl; //掉了输出cout
str="endfile";
string s="string object type";
str+="mark"; //+=是连接符号
str.insert(3,"-of-"); //掉了双引号
str.erase(7,7);
str.erase(3,4);
cout<<s<<endl;
}
6 回复
#2
孤魂居士2007-11-09 18:49

错误如下

Compiling...
数据结构.cpp
F:\1000\数据结构.cpp(4) : error C2146: syntax error : missing ';' before identifier 'str'
F:\1000\数据结构.cpp(4) : error C2501: 'string' : missing storage-class or type specifiers
F:\1000\数据结构.cpp(4) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.

58585.exe - 1 error(s), 0 warning(s)

#3
孤魂居士2007-11-09 22:06

兄弟们跑哪里去溜达啦 看看我的贴啊``我等哦
#4
孤魂居士2007-11-09 22:08



兄弟们斑竹门怎么不溜达我的贴啊``错误不知道什么意思

#5
海子星竹2007-11-09 22:13
#include<iostream>
#include<string>
using namespace std; //这句用.h就不能用
string str = "mississ ippi";
void main()
{
int index;
index=str.find_first_of('s',0); //找字符C的位置,从0位置开始找
cout<<index<<endl;
index=str.find_first_of('s',4); //找字符s位置,从第4个位置开始找起
cout<<index<<endl;
index=0;
while((index=str.find_first_of('i',index))!=-1) //这里掉了一对括号
{
cout<<"index:"<<index<<" "<<endl;index++;
}
index=str.find_last_of(' ');
string firstname,lastname; //firstname中间没有空格
firstname=str.substr(0,index);
lastname=str.substr(index=+1,-1);
index=str.find("miss");
cout<<index<<endl;
index=str.find("ippi");
index=str.find("ippi",8);
cout<<index<<endl; //掉了输出cout
str="endfile";
string s="string object type";
str+="mark"; //+=是连接符号
str.insert(3,"-of-"); //掉了双引号
str.erase(7,7);
str.erase(3,4);
cout<<s<<endl;
}

还是少分号。
#6
孤魂居士2007-11-09 22:23
恩 OK了
谢谢楼上的兄弟
#7
小飞丫2007-11-09 22:56
强```
1