请C++高手来看看我的这串代码哪里出错了
头文件:C++顺序串.hclassstring{public:string();intlength()const;intget_int(constinti,char&x)...
头文件:C++顺序串.h
class string{
public:
string();
int length() const;
int get_int(const int i,char &x) const;
int locate(const char x) const;
int insert(const int i,const char x);
int delete_int(const int i);
int QuickSortTheList(); //这是一个用来对表进行快速排序的函数
int QuickSortTheList200();
private:
char data[1000]; //maxlen取1000
int count;
};
string::string(){count=0;}
int string::length() const
{return count;}
int string::get_int(const int i,char &x)const{
if(i<=0||i>count) return -1;
x=data[i-1];
return 1;
}
int string::locate(const char x)const{
for(int i=0;i<length();i++)
if(data[i]==x) return(i+1);
return -1;
}
int string::insert(const int i,const char x){
if(count==1000)
return 0;
if(i<1||i>length()+1)
return 0;
for(int j=count-1;j>=i-1;j--)
data[j+1]=data[j];
data[i-1]=x;
count++;
return 1;
}
int string::delete_int(const int i){
if(length()==0)
return 0;
if(i<1||i>length())
return 0;
for(int j=i+1;j<=length();j++)
data[j-2]=data[j-1];
count--;
return 1;
}
下面是一个实验locate函数好不好用的cpp:
#include<iostream>
using namespace std;
#include"C++顺序串.h"
int main()
{
string a;
for(i=1;i<=10;i++)
{
char m;
cin>>m;
a.insert(m,i);
}
char q;
cout<<"请输入要查找的字符";
cin>>q;
cout<<a.locate(q)<<endl;
}
程序无法运行,下面是错误提示:
In file included from /Users/czy/Desktop/我的程序设计作业/第七次作业/aqq.cpp:1:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iostream:38:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/ios:216:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__locale:15:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string:439:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:628:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/memory:604:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iterator:341:10: fatal error: '__debug' file not found
#include <__debug>
^
1 error generated.
[Finished in 0.4s with exit code 1]
[shell_cmd: g++ "/Users/czy/Desktop/我的程序设计作业/第七次作业/aqq.cpp" -o "/Users/czy/Desktop/我的程序设计作业/第七次作业/aqq"]
[dir: /Users/czy/Desktop/我的程序设计作业/第七次作业]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
我用的编译器是GCC,软件是Sublime Text。 展开
class string{
public:
string();
int length() const;
int get_int(const int i,char &x) const;
int locate(const char x) const;
int insert(const int i,const char x);
int delete_int(const int i);
int QuickSortTheList(); //这是一个用来对表进行快速排序的函数
int QuickSortTheList200();
private:
char data[1000]; //maxlen取1000
int count;
};
string::string(){count=0;}
int string::length() const
{return count;}
int string::get_int(const int i,char &x)const{
if(i<=0||i>count) return -1;
x=data[i-1];
return 1;
}
int string::locate(const char x)const{
for(int i=0;i<length();i++)
if(data[i]==x) return(i+1);
return -1;
}
int string::insert(const int i,const char x){
if(count==1000)
return 0;
if(i<1||i>length()+1)
return 0;
for(int j=count-1;j>=i-1;j--)
data[j+1]=data[j];
data[i-1]=x;
count++;
return 1;
}
int string::delete_int(const int i){
if(length()==0)
return 0;
if(i<1||i>length())
return 0;
for(int j=i+1;j<=length();j++)
data[j-2]=data[j-1];
count--;
return 1;
}
下面是一个实验locate函数好不好用的cpp:
#include<iostream>
using namespace std;
#include"C++顺序串.h"
int main()
{
string a;
for(i=1;i<=10;i++)
{
char m;
cin>>m;
a.insert(m,i);
}
char q;
cout<<"请输入要查找的字符";
cin>>q;
cout<<a.locate(q)<<endl;
}
程序无法运行,下面是错误提示:
In file included from /Users/czy/Desktop/我的程序设计作业/第七次作业/aqq.cpp:1:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iostream:38:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/ios:216:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__locale:15:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string:439:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:628:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/memory:604:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iterator:341:10: fatal error: '__debug' file not found
#include <__debug>
^
1 error generated.
[Finished in 0.4s with exit code 1]
[shell_cmd: g++ "/Users/czy/Desktop/我的程序设计作业/第七次作业/aqq.cpp" -o "/Users/czy/Desktop/我的程序设计作业/第七次作业/aqq"]
[dir: /Users/czy/Desktop/我的程序设计作业/第七次作业]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
我用的编译器是GCC,软件是Sublime Text。 展开
1个回答
展开全部
#include<iostream>
using namespace std;
class string{
};
int main(){
string a;
return 0;
}
//我的sublime用的是g++,测了这一段代码,都报错了。
//[第一个错误]error: reference to 'string' is ambiguous
//我不知道我的理解有没有错啊,你的自己定义的类string和std namespace里面的string同名了。
//希望帮到你!
//***********************
// 望采纳!o(∩_∩)o
//***********************
你是不是夜里刷题的啊!兄台~
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询