由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - for conversion from string to char*
相关主题
Pointer to iterator?请教C++中的unordered_set
请教c++的string vector问题,谢谢! (转载)c++ string 一问
stl: How to implement map idea with vector in stl ?c#中,如何写1个for loop得出"aa","ab","ac",..."zz"的所有组合?
C++ template problemC++ Strategies and Tactics 书上一个问题求助
如何把文件内容读到2D的vector里?a string define question (c++)
问一道brainbench上的问题如何动态分配内存来存储输入的不定长的字符串,char not string类型的
请教char *和char []的判断关于 exception 的一个问题
which style do you prefer?C++一个string的小问题
相关话题的讨论汇总
话题: string话题: str话题: char话题: conversion话题: vector
进入Programming版参与讨论
1 (共1页)
y*h
发帖数: 107
1
除了c_str(), 还有没有别的方法? thanks
q*****g
发帖数: 72
2
there is one way:
contrcut a vector from string,
then pass address of first element of vector:
string s("hello world");

vector v(s.begin(),s.end());

dosomething(&v[0], v.size());

【在 y*h 的大作中提到】
: 除了c_str(), 还有没有别的方法? thanks
o**o
发帖数: 3964
3
可是为什么要这样?

【在 q*****g 的大作中提到】
: there is one way:
: contrcut a vector from string,
: then pass address of first element of vector:
: string s("hello world");
:
: vector v(s.begin(),s.end());
:
: dosomething(&v[0], v.size());

q*****g
发帖数: 72
4
sometimes people have their legacy C function and try to make use of them

【在 o**o 的大作中提到】
: 可是为什么要这样?
t****t
发帖数: 6806
5
but c_str() is equivalent i think?

【在 q*****g 的大作中提到】
: sometimes people have their legacy C function and try to make use of them
q*****g
发帖数: 72
6
ya, c_str() is first choice

【在 t****t 的大作中提到】
: but c_str() is equivalent i think?
c*****e
发帖数: 11
7
1:another approach is data(), which return a memory block without '\0',
usually used in some cases requiring high efficiency, since c_str() is just
terminate()+data().
2:be careful with c_str() in some cases.
3:the vector is a kind of copy, which should be safer to some extent.
4:since c_str() return a reference pointer to the content of the string, you
'd better not change the content by c_str() and not save c_str() and use it
again. besides, due to different implementation of string, may

【在 t****t 的大作中提到】
: but c_str() is equivalent i think?
1 (共1页)
进入Programming版参与讨论
相关主题
C++一个string的小问题如何把文件内容读到2D的vector里?
C, how is a string cast into a int?问一道brainbench上的问题
pointer to function请教char *和char []的判断
char *p = "string literal"; 和 char a[] = "string liter (转载)which style do you prefer?
Pointer to iterator?请教C++中的unordered_set
请教c++的string vector问题,谢谢! (转载)c++ string 一问
stl: How to implement map idea with vector in stl ?c#中,如何写1个for loop得出"aa","ab","ac",..."zz"的所有组合?
C++ template problemC++ Strategies and Tactics 书上一个问题求助
相关话题的讨论汇总
话题: string话题: str话题: char话题: conversion话题: vector