请教这段程序在VC.NET下编译的问题,在线等待

V0id 2003-02-09 10:15:11
C++ Essential 上的:

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main ()
{
string word;
vector<string> text;

while ( cin >> word)
text.push_back(word);

sort ( text.begin(), text.end() );

for ( int ix = 0; ix < text.size(); ++ix );
~~
这里会是什么问题?
cout << text[ix] << ' ';
}

用VC.NET编译成功,但是有一个warning:
e:\Works\C\2091\2091.cpp(17): warning C4018: “<” : 有符号/无符号不匹配

而且最后编译出来的exe执行什么放映都没有?

why??
...全文
29 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
feismoke 2003-02-10
  • 打赏
  • 举报
回复
GOOD
mikespook 2003-02-10
  • 打赏
  • 举报
回复
呵,来晚了~~~~可惜,可惜~~~

一个分号,就把该循环的内容给放到了循环外啊~~~
idler 2003-02-09
  • 打赏
  • 举报
回复
这样就对了。

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main ()
{
string word;
vector<string> text;

while ( cin >> word)
text.push_back(word);

sort ( text.begin(), text.end() );

for ( int ix = 0; ix < (int)text.size(); ++ix )
cout << text[ix] << ' ';

return 0;
}
idler 2003-02-09
  • 打赏
  • 举报
回复
for ( int ix = 0; ix < text.size(); ++ix );
后面那个分号哪里来的?
V0id 2003-02-09
  • 打赏
  • 举报
回复
谢谢改成unsigned int后不抱错了

不过出来的exe还是不对,继续请问?
myall2002 2003-02-09
  • 打赏
  • 举报
回复
能过吗?main()内都没有返回值!
还有text.size()返回的是unsigned int 型

70,032

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧