如何在C++中查找字符串中出现的字符串?
这是场景.
string base_string = "BF;1;2;3;FF;10;20;30;BF;11;;22;33;FF;100;200;300;BF;110;;220;330;FF;1000;2000;3000";
string to_find_occurances_of = "BF";
Run Code Online (Sandbox Code Playgroud) 可能重复:
将字符串转换为变量名称或变量类型
如何在c ++中将字符串值用作变量名
string listName = "hari";
string vectorName = "BF_vector_"+listName;
vector<string> vectorName;
vectorName.push_back("Some Value");
Run Code Online (Sandbox Code Playgroud)
如何使用vectorName的字符串值("BF_vector_hari")作为向量的变量名.提前致谢.
我有一个结构,我试图打印其成员变量的地址.当试图通过&(fc)打印char成员变量的地址时,我没有得到他们的地址.
struct foo
{
char c;
short s;
void *p;
int i;
};
int main()
{
cout << "Size of foo: " << sizeof(foo) << endl;
foo f;
cout << "Address of c: " << reinterpret_cast<void*>(&f.c) << endl;
cout << "Address of c: " << &(f.c) << endl;
cout << "Address of s: " << reinterpret_cast<void*>(&f.s) << endl;
cout << "Address of s: " << &(f.s) << endl;
cout << "Address of p: " << reinterpret_cast<void*>(&f.p) << endl;
cout …Run Code Online (Sandbox Code Playgroud) 以下代码有什么问题?为什么打印数组的大小为零?
function test() {
var arr = [];
for(var i = 0; i < 10; i++)
{
console.log('i ->' + i);
arr.push[i];
}
console.log('\n' + 'array length :' + arr.length);
}
Run Code Online (Sandbox Code Playgroud)
-
输出:
i ->0
i ->1
i ->2
i ->3
i ->4
i ->5
i ->6
i ->7
i ->8
i ->9
array length :0
Run Code Online (Sandbox Code Playgroud)
-
打印为零(0)