Answers for "c++ take a char from string"

C++
1

how to return char* from function in c++

//Function declaration
char* testfunc()
{
    char* str = malloc(10 * sizeof(char));
    return str;
}

//Calling the function
foo = testfunc();
// Do something with your foo
free(foo);		//It is required to free() memory to avoid memory lead
Posted by: Guest on June-30-2021
1

c++ get char of string

// string::at
#include <iostream>
#include <string>

int main ()
{
  std::string str ("Test string");
  for (unsigned i=0; i<str.length(); ++i)
  {
    std::cout << str.at(i);
  }
  return 0;
}
Posted by: Guest on October-28-2020

Browse Popular Code Answers by Language