【发布时间】:2014-03-27 16:28:23
【问题描述】:
我发现唯一能帮助我的问题是C++: splitting a string into an array。 我是 C++ 的新手,我需要一个字符串数组来包含我在这个字符中的每个单词。
代码如下:
s3eFile* file = s3eFileOpen("chatTest/restrict_words.txt","rb");
int len = s3eFileGetSize(file);
char* temp = new char[len];
if (file!=NULL)
{
s3eFileRead(temp,len,1, file);
s3eFileClose(file);
}
所以我需要让这个临时文件变成一个数组,这样我就可以使用它了吗? 有办法吗?
【问题讨论】:
-
既然用的是new,为什么不用vector代替plain数组呢?
-
向量?我想没关系,我只需要知道怎么做
-
使用
std::string::find或其亲属之一。另见std::string::substr。 -
注意:
char *temp等同于char temp[],当您使用它时。如果您只想获取索引 3,则为char c = temp[3];。使用C构造时只需注意空终止符。