荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: bakey (猪朋狗友), 信区: Program
标  题: [合集][求教]: 这道题错在哪 ?
发信站: 荔园晨风BBS站 (2005年12月28日01:31:52 星期三), 站内信件

☆   1  ──────────── 我是分割线 ─────────────────☆
发信人: jaly (が勒のせ), 信区: Program
标  题: [求教]: 这道题错在哪 ?
时  间: Sun Dec 25 15:29:58 2005

#include <iostream>
#include <string>

int main()
{
        using namespace std;
}
是不是string 不能用getline 啊???


☆   2  ──────────── 我是分割线 ─────────────────☆
发信人: Yeats (冬虫夏草||粉雪), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: 2005年12月25日15:35:16 星期天

纠错题么。。还是自己编的。。
【 在 jaly (が勒のせ) 的大作中提到: 】
: #include <iostream>
: #include <string>
:
: int main()
: {
:   using namespace std;
:   string name;
:   string dessert;
:
:   cout<<"Enter your name: \n";
: .................(以下省略)



☆   3  ──────────── 我是分割线 ─────────────────☆
发信人: bso (meteor), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: Sun Dec 25 15:37:03 2005

getline的参数对吗?
istream::getline
istream& getline( char* pch, int nCount, char delim = '\n' );

istream& getline( unsigned char* puch, int nCount, char delim = '\n' );

istream& getline( signed char* psch, int nCount, char delim = '\n' );

【 在 jaly 的大作中提到: 】
: #include <iostream>
: #include <string>
:
: int main()
: {
:       using namespace std;
:       string name;
:       string dessert;
:
:       cout<<"Enter your name: \n";
:       getline(cin, name);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:       cout<<"Enter your favorite dessert: \n";
:       getline(cin, dessert);
:       cout<<"I have some delicious "<<dessert;
:       cout<<" for you, "<<name<<".\n";
:       return 0;
:
: }
: 是不是string 不能用getline 啊???



☆   4  ──────────── 我是分割线 ─────────────────☆
发信人: jaly (が勒のせ), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: Sun Dec 25 15:42:49 2005

自己编的 ^_^
【 在 Yeats 的大作中提到: 】
: 纠错题么。。还是自己编的。。
: 【 在 jaly (が勒のせ) 的大作中提到: 】
: : #include <iostream>
: : #include <string>
: :
: : int main()
: : {
: :   using namespace std;
: :   string name;
: :   string dessert;
: :
: :   cout<<"Enter your name: \n";
: : .................(以下省略)



☆   5  ──────────── 我是分割线 ─────────────────☆
发信人: jaly (が勒のせ), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: Sun Dec 25 15:45:20 2005

-_-!!! 看不懂 !
高手啊! 能不能说得浅显一点...谢谢啊
【 在 bso 的大作中提到: 】
: getline的参数对吗?
: istream::getline
: istream& getline( char* pch, int nCount, char delim = '\n' );
:
: istream& getline( unsigned char* puch, int nCount, char delim = '\n' );
:
: istream& getline( signed char* psch, int nCount, char delim = '\n' );
:
: 【 在 jaly 的大作中提到: 】
: : #include <iostream>
: : #include <string>
: :
: : int main()
: : {
: :     using namespace std;
: :     string name;
: :     string dessert;
: :
: :     cout<<"Enter your name: \n";
: :     getline(cin, name);
: (以下引言省略...)



☆   6  ──────────── 我是分割线 ─────────────────☆
发信人: starsun (小刚与微软 ), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: Sun Dec 25 15:48:31 2005

cin.getline(char *, int, char),读取由int字段指定长度的字符串,或读到char字段所指
定的字符为止。
注意的是:getline()如果在遇到回车符也会结束的,不过它和get()不同的是它会把回车符也
读进字符串中!
【 在 jaly 的大作中提到: 】
: #include <iostream>
: #include <string>
:
: int main()
: {
:       using namespace std;
:       string name;
:       string dessert;
:
:       cout<<"Enter your name: \n";
:       getline(cin, name);
:       cout<<"Enter your favorite dessert: \n";
:       getline(cin, dessert);
:       cout<<"I have some delicious "<<dessert;
:       cout<<" for you, "<<name<<".\n";
:       return 0;
:
: }
: 是不是string 不能用getline 啊???



☆   7  ──────────── 我是分割线 ─────────────────☆
发信人: bso (meteor), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: Sun Dec 25 15:49:10 2005

getline有个默认参数'\n'做为分隔符,把回车符当然字符也读取了,所以要输入两次回车~~~
~~~~~~~
【 在 jaly 的大作中提到: 】
: -_-!!! 看不懂 !
: 高手啊! 能不能说得浅显一点...谢谢啊
: 【 在 bso 的大作中提到: 】
: : getline的参数对吗?
: : istream::getline
: : istream& getline( char* pch, int nCount, char delim = '\n' );
: :
: : istream& getline( unsigned char* puch, int nCount, char delim = '\n' );
: :
: : istream& getline( signed char* psch, int nCount, char delim = '\n' );
: :
: : (以下引言省略...)



☆   8  ──────────── 我是分割线 ─────────────────☆
发信人: kaman (天外飛仙), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: 2005年12月25日15:50:30 星期天


- -你把getline重载啦?ft

【 在 bso (meteor) 的大作中提到: 】
: getline有个默认参数'\n'做为分隔符,把回车符当然字符也读取了,所以要输入两次回车~
: ~~~~~~~
: 【 在 jaly 的大作中提到: 】
: : -_-!!! 看不懂 !
: : 高手啊! 能不能说得浅显一点...谢谢啊
: : 【 在 bso 的大作中提到: 】



☆   9  ──────────── 我是分割线 ─────────────────☆
发信人: starsun (小刚与微软 ), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: Sun Dec 25 15:50:40 2005

还有就是你的.....
#include <iostream.h>
#include <string.h>

!!!
【 在 jaly 的大作中提到: 】
: #include <iostream>
: #include <string>
:
: int main()
: {
:       using namespace std;
:       string name;
:       string dessert;
:
:       cout<<"Enter your name: \n";
:       getline(cin, name);
:       cout<<"Enter your favorite dessert: \n";
:       getline(cin, dessert);
:       cout<<"I have some delicious "<<dessert;
:       cout<<" for you, "<<name<<".\n";
:       return 0;
:
: }
: 是不是string 不能用getline 啊???



☆  10  ──────────── 我是分割线 ─────────────────☆
发信人: kaman (天外飛仙), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: 2005年12月25日15:51:37 星期天


看不到using namespace std;么?

【 在 starsun (小刚与微软 ) 的大作中提到: 】
: 还有就是你的.....
: #include <iostream.h>
: #include <string.h>
:
: !!!
: 【 在 jaly 的大作中提到: 】
: : #include <iostream>
: : #include <string>
: :
: : int main()
: .................(以下省略)



☆  11  ──────────── 我是分割线 ─────────────────☆
发信人: kaman (天外飛仙), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: 2005年12月25日15:51:57 星期天


不同的getline来的

【 在 bso (meteor) 的大作中提到: 】
: getline的参数对吗?
: istream::getline
: istream& getline( char* pch, int nCount, char delim = '\n' );
:
: istream& getline( unsigned char* puch, int nCount, char delim = '\n' );
:
: istream& getline( signed char* psch, int nCount, char delim = '\n' );
:
: 【 在 jaly 的大作中提到: 】
: : #include <iostream>
: .................(以下省略)



☆  12  ──────────── 我是分割线 ─────────────────☆
发信人: Yeats (冬虫夏草||粉雪), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: 2005年12月25日15:52:04 星期天

c++里可以不用.h的~~~
后面用using namespace std;了。。
【 在 starsun (小刚与微软 ) 的大作中提到: 】
: 还有就是你的.....
: #include <iostream.h>
: #include <string.h>
:
: !!!
: 【 在 jaly 的大作中提到: 】
: : #include <iostream>
: : #include <string>
: :
: : int main()
: .................(以下省略)



☆  13  ──────────── 我是分割线 ─────────────────☆
发信人: kaman (天外飛仙), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: 2005年12月25日15:52:21 星期天


在g++编译没问题啊,你是编译不过还是怎样?

【 在 jaly (が勒のせ) 的大作中提到: 】
: #include <iostream>
: #include <string>
:
: int main()
: {
:   using namespace std;
:   string name;
:   string dessert;
:
:   cout<<"Enter your name: \n";
: .................(以下省略)



☆  14  ──────────── 我是分割线 ─────────────────☆
发信人: Yeats (冬虫夏草||粉雪), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: 2005年12月25日15:53:26 星期天

g++是什么玩意?
【 在 kaman (天外飛仙) 的大作中提到: 】
: 在g++编译没问题啊,你是编译不过还是怎样?
: 【 在 jaly (が勒のせ) 的大作中提到: 】
: : #include <iostream>
: : #include <string>
: : int main()
: : {
: :   using namespace std;
: :   string name;
: :   string dessert;
: :   cout<<"Enter your name: \n";
: .................(以下省略)



☆  15  ──────────── 我是分割线 ─────────────────☆
发信人: bso (meteor), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: Sun Dec 25 15:54:27 2005

#include <iostream.h>  这种方式是旧的C++方式,旧方式使用cout不要求using namespace
 std;
#include <iostream>  这是新的C++方式,新的方式使用cout等要求using namespace std;

【 在 starsun 的大作中提到: 】
: 还有就是你的.....
: #include <iostream.h>
: #include <string.h>
:
: !!!
: 【 在 jaly 的大作中提到: 】
: : #include <iostream>
: : #include <string>
: :
: : int main()
: : {
: :     using namespace std;
: :     string name;
: :     string dessert;
: :
: :     cout<<"Enter your name: \n";
: :     getline(cin, name);
: :     cout<<"Enter your favorite dessert: \n";
: :     getline(cin, dessert);
: :     cout<<"I have some delicious "<<dessert;
: (以下引言省略...)



☆  16  ──────────── 我是分割线 ─────────────────☆
发信人: starsun (小刚与微软 ), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: Sun Dec 25 15:54:41 2005

这个倒是不知道,呵呵,不好意思.
【 在 Yeats 的大作中提到: 】
: c++里可以不用.h的~~~
: 后面用using namespace std;了。。
: 【 在 starsun (小刚与微软 ) 的大作中提到: 】
: : 还有就是你的.....
: : #include <iostream.h>
: : #include <string.h>
: :
: : !!!
: : .................(以下省略)



☆  17  ──────────── 我是分割线 ─────────────────☆
发信人: jaly (が勒のせ), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: Sun Dec 25 15:55:32 2005

第一个输入要两个回车...结果是第一个回车跟第二个回车的输入是第二个输入的
【 在 kaman 的大作中提到: 】
: 在g++编译没问题啊,你是编译不过还是怎样?
: 【 在 jaly (が勒のせ) 的大作中提到: 】
: : #include <iostream>
: : #include <string>
: :
: : int main()
: : {
: :   using namespace std;
: :   string name;
: :   string dessert;
: :
: :   cout<<"Enter your name: \n";
: : .................(以下省略)



☆  18  ──────────── 我是分割线 ─────────────────☆
发信人: Yeats (冬虫夏草||粉雪), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: 2005年12月25日15:55:49 星期天

c++里编译没问题。。你运行下就知道问题了。。
要输入3次。。取前两次的值而已。。
【 在 kaman (天外飛仙) 的大作中提到: 】
: 在g++编译没问题啊,你是编译不过还是怎样?
: 【 在 jaly (が勒のせ) 的大作中提到: 】
: : #include <iostream>
: : #include <string>
: : int main()
: : {
: :   using namespace std;
: :   string name;
: :   string dessert;
: :   cout<<"Enter your name: \n";
: .................(以下省略)



☆  19  ──────────── 我是分割线 ─────────────────☆
发信人: kaman (天外飛仙), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: 2005年12月25日15:56:02 星期天


the c++ compiler of GNU...

【 在 Yeats (冬虫夏草||粉雪) 的大作中提到: 】
: g++是什么玩意?
: 【 在 kaman (天外飛仙) 的大作中提到: 】
: : 在g++编译没问题啊,你是编译不过还是怎样?
: : .................(以下省略)



☆  20  ──────────── 我是分割线 ─────────────────☆
发信人: jaly (が勒のせ), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: Sun Dec 25 15:56:58 2005

我用的是c++6.0 ms 再新的版本好像可以...
【 在 kaman 的大作中提到: 】
: 在g++编译没问题啊,你是编译不过还是怎样?
: 【 在 jaly (が勒のせ) 的大作中提到: 】
: : #include <iostream>
: : #include <string>
: :
: : int main()
: : {
: :   using namespace std;
: :   string name;
: :   string dessert;
: :
: :   cout<<"Enter your name: \n";
: : .................(以下省略)



☆  21  ──────────── 我是分割线 ─────────────────☆
发信人: Yeats (冬虫夏草||粉雪), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: 2005年12月25日15:58:05 星期天

*_*+++
GNU。。open source?
【 在 kaman (天外飛仙) 的大作中提到: 】
: the c++ compiler of GNU...
: 【 在 Yeats (冬虫夏草||粉雪) 的大作中提到: 】
: : g++是什么玩意?



☆  22  ──────────── 我是分割线 ─────────────────☆
发信人: kaman (天外飛仙), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: 2005年12月25日15:58:27 星期天


g++编译出来的运行也没这个问题,

或者试试改getline那些为

cin.getline(str,100);

试试

【 在 Yeats (冬虫夏草||粉雪) 的大作中提到: 】
: c++里编译没问题。。你运行下就知道问题了。。
: 要输入3次。。取前两次的值而已。。
: 【 在 kaman (天外飛仙) 的大作中提到: 】
: : 在g++编译没问题啊,你是编译不过还是怎样?
: : .................(以下省略)



☆  23  ──────────── 我是分割线 ─────────────────☆
发信人: kaman (天外飛仙), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: 2005年12月25日15:58:39 星期天


bingo。。

【 在 Yeats (冬虫夏草||粉雪) 的大作中提到: 】
: *_*+++
: GNU。。open source?
: 【 在 kaman (天外飛仙) 的大作中提到: 】
: : the c++ compiler of GNU...



☆  24  ──────────── 我是分割线 ─────────────────☆
发信人: crycz (打印刻录CD/DVD  javaLover), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: 2005年12月25日16:01:22 星期天

没问题呀...不像你所说那样啊..

运行结果:
Enter your name:
blues
Enter your favorite dessert:
apple
I have some delicious apple for you,blues.
Press any key to continue

【 在 Yeats (冬虫夏草||粉雪) 的大作中提到: 】
: c++里编译没问题。。你运行下就知道问题了。。
: 要输入3次。。取前两次的值而已。。
: 【 在 kaman (天外飛仙) 的大作中提到: 】
: : 在g++编译没问题啊,你是编译不过还是怎样?
: : .................(以下省略)


☆  25  ──────────── 我是分割线 ─────────────────☆
发信人: crycz (打印刻录CD/DVD  javaLover), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: 2005年12月25日16:02:27 星期天

都是一次回车...

我用的是.net 2003

【 在 crycz (打印刻录CD/DVD  javaLover) 的大作中提到: 】
: 没问题呀...不像你所说那样啊..
: 运行结果:
: Enter your name:
: blues
: Enter your favorite dessert:
: apple
: I have some delicious apple for you,blues.
: Press any key to continue
: 【 在 Yeats (冬虫夏草||粉雪) 的大作中提到: 】
: : c++里编译没问题。。你运行下就知道问题了。。
: .................(以下省略)


☆  26  ──────────── 我是分割线 ─────────────────☆
发信人: Yeats (冬虫夏草||粉雪), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: 2005年12月25日16:02:59 星期天

难道vc的问题。。- -|||
【 在 crycz (打印刻录CD/DVD  javaLover) 的大作中提到: 】
: 没问题呀...不像你所说那样啊..
: 运行结果:
: Enter your name:
: blues
: Enter your favorite dessert:
: apple
: I have some delicious apple for you,blues.
: Press any key to continue
: 【 在 Yeats (冬虫夏草||粉雪) 的大作中提到: 】
: : c++里编译没问题。。你运行下就知道问题了。。
: .................(以下省略)



☆  27  ──────────── 我是分割线 ─────────────────☆
发信人: crycz (打印刻录CD/DVD  javaLover), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: 2005年12月25日16:04:00 星期天

早不用VC了...觉得超多问题...
我的VC连string都用不了

【 在 Yeats (冬虫夏草||粉雪) 的大作中提到: 】
: 难道vc的问题。。- -|||
: 【 在 crycz (打印刻录CD/DVD  javaLover) 的大作中提到: 】
: : 没问题呀...不像你所说那样啊..
: : 运行结果:
: : Enter your name:
: : blues
: : Enter your favorite dessert:
: : apple
: : I have some delicious apple for you,blues.
: : Press any key to continue
: .................(以下省略)


☆  28  ──────────── 我是分割线 ─────────────────☆
发信人: starsun (小刚与微软 ), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: Sun Dec 25 16:05:00 2005

我已重装过N遍.
【 在 crycz 的大作中提到: 】
: 早不用VC了...觉得超多问题...
: 我的VC连string都貌涣?: 【 在 Yeats (冬虫夏草||粉雪) 的大作中提到: 】
: : 难道vc的问题。。- -|||
: : .................(以下省略)



☆  29  ──────────── 我是分割线 ─────────────────☆
发信人: jaly (が勒のせ), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: Sun Dec 25 16:05:02 2005

看来版本不同getline 的定义也不同...-_-#!
【 在 crycz 的大作中提到: 】
: 都是一次回车...
: 我用的是.net 2003
: 【 在 crycz (打印刻录CD/DVD  javaLover) 的大作中提到: 】
: : 没问题呀...不像你所说那样啊..
: : 运行结果:
: : Enter your name:
: : blues
: : Enter your favorite dessert:
: : apple
: : I have some delicious apple for you,blues.
: : Press any key to continue
: : .................(以下省略)



☆  30  ──────────── 我是分割线 ─────────────────☆
发信人: kaman (天外飛仙), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: 2005年12月25日16:07:07 星期天


就是vc6的问题,哈哈

【 在 Yeats (冬虫夏草||粉雪) 的大作中提到: 】
: 难道vc的问题。。- -|||
: 【 在 crycz (打印刻录CD/DVD  javaLover) 的大作中提到: 】
: : 没问题呀...不像你所说那样啊..
: : 运行结果:
: : Enter your name:
: : blues
: : Enter your favorite dessert:
: : apple
: : I have some delicious apple for you,blues.
: : Press any key to continue
: .................(以下省略)



☆  31  ──────────── 我是分割线 ─────────────────☆
发信人: jaly (が勒のせ), 信区: Program
标  题: Re: [求教]: 这道题错在哪 ?
时  间: Sun Dec 25 16:09:14 2005

-_-!!!
【 在 kaman 的大作中提到: 】
: 就是vc6的问题,哈哈
: 【 在 Yeats (冬虫夏草||粉雪) 的大作中提到: 】
: : 难道vc的问题。。- -|||
: : .................(以下省略)


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店