鱼C论坛

 找回密码
 立即注册
查看: 3459|回复: 2

string类型的vector输入,为什么这样不行?

[复制链接]
发表于 2012-6-28 23:30:11 | 显示全部楼层 |阅读模式
5鱼币
#include <iostream>
#include <string>
#include <vector>

using std::string;
using std::vector;

int main()
{
    string str_s;
    std::cout << "input the strings:" << std::endl;
    while(std::cin >> str_s)
    {
        vector<string> str_v(str_s);
    }

}
why?why??why??? GOD HELP ME ~~~

小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-6-29 01:55:33 | 显示全部楼层
vector<string> 前面定义好
后面直接添加 push_back
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2012-6-29 07:01:36 | 显示全部楼层
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>

  4. using std::string;
  5. using std::vector;

  6. int main()
  7. {
  8.         vector<string> str_v;
  9.     string str_s;
  10.     std::cout << "input the strings:" << std::endl;
  11.     while(std::cin >> str_s)
  12.     {
  13.         str_v.push_back(str_s);
  14.     }

  15.         for( int i=0; i<str_v.size();++i )
  16.         {
  17.                 std::cout<<str_v[i]<<std::endl;
  18.         }
  19. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-13 23:48

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表