我有这样的主要功能:
void main()
{
char *s;
inputString(s);
printf("%s",s);
}
和 inputString 函数:
void inputString(char *&s)
{
//Some code line to input a string and set s point to this string
}
是否有一个函数auto malloc memory enough store string which input(我需要在inputString函数中输入字符串)。
最佳答案
只需 3 行代码(将它们放在 int main()
中)就足够了
std::string s;
std::cin >> s; //or getline() as desired
std::cout << s;
关于c++ - 如何在 C 中使用 char *,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4378411/