| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1680 人关注过本帖
标题:[求助]改一个错误
只看楼主 加入收藏
W649897
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2006-11-26
收藏
 问题点数:0 回复次数:10 
[求助]改一个错误
//输入三个字符串,按由大到小的顺序输出
//用string的方法
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main()
{
string str1,str2,str3;
cout<<"enter three strings:";
getline(cin,str1);
getline(cin,str2);
getline(cin,str3);
void swap(string &,string &);
if(str1>str2)
swap(str1,str2);
if(str1>str3)
swap(str1,str3);
if(str2>str3)
swap(str2,str3);
cout<<str1<<endl<<str2<<endl<<str3<<endl;
return 0;
}
void swap(string&str,string&str4)
{
string temp;
temp=str;str=str4;str4=temp;
}
错误提示
pr02.obj : fatal error LNK1179: invalid or corrupt file: duplicate comdat "?swap@@YAXAAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z"
搜索更多相关主题的帖子: string swap cin getline include 
2006-12-13 15:31
xjc
Rank: 1
等 级:新手上路
帖 子:95
专家分:0
注 册:2004-12-2
收藏
得分:0 

void swap(string &,string &);

放到MAIN()外去


时间是最宝贵的
2006-12-13 23:23
smartwind
Rank: 1
等 级:新手上路
威 望:1
帖 子:277
专家分:0
注 册:2006-11-13
收藏
得分:0 
应该是放到上面吧

2006-12-15 11:33
爱上夜
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2006-9-12
收藏
得分:0 
把交换函数放到主函数上面
如果你不想的话
你可以把void swap(string&str,string&str4);这个语句放到主函数上面
这是VC++与TC不同之一

2006-12-16 16:38
Ling灵仔
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-12-16
收藏
得分:0 

你这个程序好像很多问题哟:
1,#include<cstring>可以不用了吧,多余;
2,如上面所说,函数声明有误;
3,你的数据输入有误,可以输入四个字符,但第四个又不参与比较;
4,if语句中有误,如果if语句这样排,cout语句也这样输出,那么你的是按小到大排列,而不是按大到小排列;

不过我也从你这学到了不少东西:
1,using namespace std;我第一次见,具体用法还不太清楚呢;
2,int main()这种主函数也学到了,用return 0;作返回;


我还是一个学生,还有待进步,只看出了一点小毛病,,希望以后大家一起学习..


编程是种艺术!
2006-12-16 20:49
Ling灵仔
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-12-16
收藏
得分:0 
#include<iostream>
#include<string>
using namespace std;
void swap(string&str,string&str4);
void main()
{
string str1,str2,str3;
cout<<"enter three strings:"<<endl;
cin>>str1>>str2>>str3;
if(str2>str1)
swap(str1,str2);
if(str3>str1)
swap(str1,str3);
if(str3>str2)
swap(str2,str3);
cout<<str1<<endl<<str2<<endl<<str3<<endl;

}
void swap(string&str,string&str4)
{
string temp;
temp=str;str=str4;str4=temp;
}

你可以参考下我改写的这个程序,可以达到目的,
各位,我有一个问题想不明白:using namespace std;哪里限制了它一定要,如果我不要它,应该怎么样改?


编程是种艺术!
2006-12-16 20:55
W649897
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2006-11-26
收藏
得分:0 

谢谢拉

2006-12-17 09:32
W649897
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2006-11-26
收藏
得分:0 

但是如果改到外面去就有14个错误如下
C:\Documents and Settings\user3_086\My Documents\My eBooks\chapter6\p3.cpp(49) : error C2065: 'string' : undeclared identifier
C:\Documents and Settings\user3_086\My Documents\My eBooks\chapter6\p3.cpp(49) : error C2059: syntax error : ','
C:\Documents and Settings\user3_086\My Documents\My eBooks\chapter6\p3.cpp(53) : error C2872: 'string' : ambiguous symbol
C:\Documents and Settings\user3_086\My Documents\My eBooks\chapter6\p3.cpp(53) : error C2872: 'string' : ambiguous symbol
C:\Documents and Settings\user3_086\My Documents\My eBooks\chapter6\p3.cpp(53) : error C2146: syntax error : missing ';' before identifier 'str1'
C:\Documents and Settings\user3_086\My Documents\My eBooks\chapter6\p3.cpp(53) : error C2065: 'str1' : undeclared identifier
C:\Documents and Settings\user3_086\My Documents\My eBooks\chapter6\p3.cpp(53) : error C2065: 'str2' : undeclared identifier
C:\Documents and Settings\user3_086\My Documents\My eBooks\chapter6\p3.cpp(53) : error C2065: 'str3' : undeclared identifier
C:\Documents and Settings\user3_086\My Documents\My eBooks\chapter6\p3.cpp(67) : error C2872: 'string' : ambiguous symbol
C:\Documents and Settings\user3_086\My Documents\My eBooks\chapter6\p3.cpp(67) : error C2872: 'string' : ambiguous symbol
C:\Documents and Settings\user3_086\My Documents\My eBooks\chapter6\p3.cpp(67) : error C2065: 'str' : undeclared identifier
C:\Documents and Settings\user3_086\My Documents\My eBooks\chapter6\p3.cpp(67) : error C2872: 'string' : ambiguous symbol
C:\Documents and Settings\user3_086\My Documents\My eBooks\chapter6\p3.cpp(67) : error C2065: 'str4' : undeclared identifier
C:\Documents and Settings\user3_086\My Documents\My eBooks\chapter6\p3.cpp(68) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
Error executing cl.exe.

chapter6.exe - 14 error(s), 0 warning(s)

2006-12-17 09:37
W649897
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2006-11-26
收藏
得分:0 
上面的问题已解决但,提示又说什么该内存不能为written,什么意思呀
2006-12-17 09:41
Ling灵仔
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-12-16
收藏
得分:0 
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
void swap(string &,string &);
int main()
{
string str1,str2,str3;
cout<<"enter three strings:";
getline(cin,str1);
getline(cin,str2);
getline(cin,str3);

if(str1>str2)
swap(str1,str2);
if(str1>str3)
swap(str1,str3);
if(str2>str3)
swap(str2,str3);
cout<<str1<<endl<<str2<<endl<<str3<<endl;
return 0;
}
void swap(string&str,string&str4)
{
string temp;
temp=str;str=str4;str4=temp;
}
不会呀,你看下,这样运行哪有错呀?能运行!
我想知道如果不用using namespace std;应该怎么样改, 我改过好多次了,还是不行的,,,请指教!谢谢!

编程是种艺术!
2006-12-17 13:39
快速回复:[求助]改一个错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017019 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved