Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何将字符串添加到C++;_C++_String_Vector_Add - Fatal编程技术网

C++ 如何将字符串添加到C++;

C++ 如何将字符串添加到C++;,c++,string,vector,add,C++,String,Vector,Add,我有: vector*历史; 历史=新向量[300]; 其中历史记录应包含多个字符串(最多300个) 然后我要添加一个字符串: vector<string> *history; history = new vector<string>[300]; std::stringstream sstm; sstm您在此处动态分配向量的数组: std::stringstream sstm; sstm << frameProc << " "; string

我有:

vector*历史;
历史=新向量[300];
其中历史记录应包含多个字符串(最多300个)

然后我要添加一个字符串:

vector<string> *history;
history = new vector<string>[300];
std::stringstream sstm;

sstm您在此处动态分配
向量的数组:

std::stringstream sstm;
sstm << frameProc << " ";
string result = sstm.str();
history[xyz]= result;  //This line does not work
vector*历史;
历史=新向量[300];
您真正需要的是字符串向量:

vector<string> *history;
history = new vector<string>[300];
std::向量历史;
标准:stringstream sstm;

sstm如果要回答您的问题

如何在C中向字符串向量添加字符串++

然后按照下面的方法进行

std::vector<std::string> history;
std::stringstream sstm;
sstm << frameProc << " ";
std::string result = sstm.str();
history.push_back(result);

如果要考虑代码段,则正确的语句将查看

v.insert( v.end(), "Some string" );

编辑:

我还想,也许你做错了什么,但我不明白你在做什么。然后考虑下面的代码。也许会有帮助

history[xyz].insert( history[xyz].end(), result );
std::向量历史(300);
//...
历史[xyz]+=结果;

但我希望将每个字符串作为一个完整的字符串。我应该把它改成历史吗;那么?@user3236180对不起,我的意思是
push_back(result)
(或者
push_back(sstm.str())
)这不起作用,因为
result
是一个
字符串
,但是
历史
是一个
向量数组
@Manu343726:在我看来,OP根本不需要
向量
。他们想要一组(最多)300个
string
s。他们在这里做了完全错误的事情。(关于没有阅读省略的文档的咆哮)
history[xyz].push_back( result );
history[xyz].insert( history[xyz].end(), result );
std::vector<std::string> history( 300 );
//...
history[xyz] += result;