指针指针 [英] Pointer to Pointer
问题描述
如何手动添加一个字符串数组,这是一个指针指针,
例如
char ** str;
//添加this,is,a,test等一个接一个地进入2D阵列?
谢谢。
Hi,
How to manually add an array of string, which is pointer by a pointer,
e.g.
char **str;
// add "this", "is", "a", "test" one by one into the 2d array?
thanks.
推荐答案
howa写道:
howa wrote:
如何手动添加一个字符串数组,这是一个指针指针,
Hi,
How to manually add an array of string, which is pointer by a pointer,
在C ++中,字符串表示std :: string类:
#include< string>
std :: string mystring ="这是一个字符串" ;;
你可能意味着什么是C风格的字符数组,但它是
建议你用C ++来避免它们。
In C++ a string means the std::string class:
#include <string>
std::string mystring = "this is a string";
What you probably mean is a C-style array of chars, but it is
recommended that you avoid them in C++.
char ** str;
// add"这个,是,,a,测试,一个接一个地进入2d阵列?
char **str;
// add "this", "is", "a", "test" one by one into the 2d array?
你有一个指针,而不是二维数组。想到
双指针作为数组是非常非常错误的。
无论如何,你应该使用标准的字符串向量:
#include< vector>
#include< string>
std :: vector< std :: stringmystrings ;
mystrings.push_back(" some string");
mystrings [0]; //< - 你可以像任何阵列一样访问矢量
问候,
Bart。
You have a pointer, not a 2D array. It is very, VERY wrong to think of
double-pointers as arrays.
Anyway, you should use a standard vector of strings instead:
#include <vector>
#include <string>
std::vector<std::stringmystrings;
mystrings.push_back("some string");
mystrings[0]; // <-- you access the vector just like any array
Regards,
Bart.
Bart?ˉ?é?????
Bart ?ˉ?é?????
howa写道:
howa wrote:
如何手动添加一个字符串数组,这是一个指针指针,
Hi,
How to manually add an array of string, which is pointer by a pointer,
在C ++中,字符串表示std :: string类:
#include< string>
std: :string mystring ="这是一个字符串" ;;
你可能意味着什么是C风格的字符数组,但是建议使用
你用C ++来避免它们。
In C++ a string means the std::string class:
#include <string>
std::string mystring = "this is a string";
What you probably mean is a C-style array of chars, but it is
recommended that you avoid them in C++.
char ** str;
//添加this,是 ;,a,测试,一个接一个地进入2d阵列?
char **str;
// add "this", "is", "a", "test" one by one into the 2d array?
你有一个指针,而不是二维数组。想到
双指针作为数组是非常非常错误的。
无论如何,你应该使用标准的字符串向量:
#include< vector>
#include< string>
std :: vector< std :: stringmystrings ;
mystrings.push_back(" some string");
mystrings [0]; //< - 你可以像任何阵列一样访问矢量
问候,
巴特。
You have a pointer, not a 2D array. It is very, VERY wrong to think of
double-pointers as arrays.
Anyway, you should use a standard vector of strings instead:
#include <vector>
#include <string>
std::vector<std::stringmystrings;
mystrings.push_back("some string");
mystrings[0]; // <-- you access the vector just like any array
Regards,
Bart.
是否可以使用char *动态创建?
就像int main(char ** argv)一样?
谢谢。
is it possible to create dynamically using char* ?
just like the int main(char **argv) ?
thanks.
Bart写道:
Bart wrote:
howa写道:
howa wrote:
>
如何手动添加一个字符串数组,这是一个指针指针,
>Hi,
How to manually add an array of string, which is pointer by a pointer,
在C ++中,字符串表示std :: string类:
#include< string>
std :: string mystring ="这是一个字符串" ;;
In C++ a string means the std::string class:
#include <string>
std::string mystring = "this is a string";
当文本明确指出C风格的字符串时。
-
- Pete
标准C ++库扩展的作者:教程和
参考。有关本书的更多信息,请参阅
www.petebecker.com/tr1book。
这篇关于指针指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!