以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 C/C++编程思想 』  (http://bbs.xml.org.cn/list.asp?boardid=61)
----  请教vector使用中遇到的俩个错误!  (http://bbs.xml.org.cn/dispbbs.asp?boardid=61&rootid=&id=30456)


--  作者:jdsun
--  发布时间:4/12/2006 9:20:00 PM

--  请教vector使用中遇到的俩个错误!
#include<iostream.h>
#include<vector>
#include<string.h>
using namespace std;
using std:: vector;

void main ()
{
 string word;
 vector <string> text ;
 cout<<"please input some words:"<<endl;
 while (cin>> word)
 {
  text.push_back(word);
 }
}
这段编译时的错误:
1):error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char
> >' (or there is no acceptable conversion)
2):fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.
请问这是什么原因?
(我刚接触c++不久,发现最难的不是学,而是用)


--  作者:elfstone
--  发布时间:4/13/2006 9:08:00 AM

--  
#include "iostream"
#include "vector"
#include "string"
using namespace std;
int main ()
{
    string word;
    vector <string> text ;
    cout<<"please input some words:"<<endl;
    getline(cin,word);
    while(word!="")
    {
       text.push_back(word);
       getline(cin,word);
    }
    for(int i=0;i<text.size();i++)
        cout<<text[i]<<endl;
    system("PAUSE");
    return 0;
}
--  作者:elfstone
--  发布时间:4/13/2006 9:09:00 AM

--  
注意头文件的声明方式。。。
--  作者:jdsun
--  发布时间:4/14/2006 9:14:00 AM

--  
谢谢指教!
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
62.500ms