#include <iostream.h>
#include <string>
using namespace std;
int main()
{
// 初始化一个string 对象用来存放搜索的结果
string search_word = "sunnic";
// 把一个bool 变量初始化为false
bool found = false;
//bool founds =true;
string next_word;
while ( cin >> next_word)
if ( next_word == search_word )
found = true;
// ...
// 缩写, 相当于: if ( found == true )
if ( found )
cout << "ok, we found the word\n";
else cout << "nope, the word was not present.\n"; return 0;
}
while ( cin >> next_word)
这句老是通不过,如何解决?
#include <string>
using namespace std;
int main()
{
// 初始化一个string 对象用来存放搜索的结果
string search_word = "sunnic";
// 把一个bool 变量初始化为false
bool found = false;
//bool founds =true;
string next_word;
while ( cin >> next_word)
if ( next_word == search_word )
found = true;
// ...
// 缩写, 相当于: if ( found == true )
if ( found )
cout << "ok, we found the word\n";
else cout << "nope, the word was not present.\n"; return 0;
}
while ( cin >> next_word)
这句老是通不过,如何解决?
解决方案 »
- CFile写文件的问题
- (倾家荡产求答案)绘制菜单弹出箭头以及部分菜单项不能修改其高度的问题
- 谁有DirectX9.03D游戏开发编程基础的电子版?
- 现在C++主要的应用有哪些,跟什么技术会比较好
- 请问COlePropertyPage应该怎么使用呢?这个类的相关资料太少,拜托各位前辈了!
- 请教一下:我现在写一个图形处理的程序,有一些疑问。大概是关于保存图象颜色的。
- 程序需要分模块的情况下,各模块是应该直接做成com还是只做成dll比较好?
- 推荐一个VC交流学习的高级群5497193(VC技术联盟)
- 新手:请大家帮忙,讲讲封装动态链接库的步骤,谢谢了!!!急......!!!
- 求助:GINA连接web server
- 怎样获取当前系统中所有应用程序进程id的列表?
- 请问如何打包?
给它一个空间,要不你就动态分配
#include <string>
using namespace std;
int main()
{
// 初始化一个string 对象用来存放搜索的结果
string search_word = "sunnic";
// 把一个bool 变量初始化为false
bool found = false;
bool founds =true;
string next_word;
while ( cin >> next_word){
if ( next_word == search_word ){
found = true;
break;
}
}
// ... // 缩写, 相当于: if ( found == true )
if ( found )
cout << "ok, we found the word\n";
else cout << "nope, the word was not present.\n";
return 0;
}
我是在LINUX下g++编译的!!!!!!!
可以用
char next_word[100];
while(cin>>next_word)
{
if(next_word == search_word ) found = true;
....
}
但cin>>next_word仍然是返回输入流,while(cin>>next_word)将不会终止
所以应该另外寻找出口。
另外next_word的缓冲区大小要注意检查...