C++字符串问题

[复制链接]
查看11 | 回复2 | 2011-4-5 19:18:17 | 显示全部楼层 |阅读模式
输入N个字符串 N由用户输入 在用户输入N值后怎么定义N个字符串 谢谢
例如输入5 程序运行时就能定义5个string字符串 如果输入4 就定义4个

回复

使用道具 举报

千问 | 2011-4-5 19:18:17 | 显示全部楼层
像下边这样就可以了,使用vector存放字符串,输入的个数,通过重新设置vector的大小,就可以满足要求了。#include#include#includeusing namespace std;int main(void){ int n; std::cout > n; std::vector strCont; strCont.resize(n); std::cout #includeusing namespace std;int main(){ int num; cin>>num; string* str=new string[num]; for(int i=0;i>pArr[0];delete []pArr; //使用完后释放内存另外一种是使用
回复

使用道具 举报

千问 | 2011-4-5 19:18:17 | 显示全部楼层
std::string* strArray = new std::string[N];这个意思?
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行