This is because you have not allocate your objects prior to using them:
string * firstName = new string(); //... delete firstName;
It’s worth adding that using pointers in this situation is, well, pointless: string objects in the standard C++ library allocate the data for the string from the heap; strings are usually not much more than a pair of pointers anyway.
Related Posts:
- C++ – Assigning null to a std::string
- Function stoi not declared
- Function stoi not declared
- What are the differences between a pointer variable and a reference variable in C++?
- Easiest way to convert int to string in C++
- C++ — expected primary-expression before ‘ ‘
- What is `CString`?
- Return array in a function
- What does “dereferencing” a pointer mean?
- Regular cast vs. static_cast vs. dynamic_cast
- What is a smart pointer and when should I use one?
- What does “dereferencing” a pointer mean?
- What is a char*?
- How do I include the string header?
- What exactly is nullptr?
- Differences between C++ string == and compare()?
- How to convert a char array to a string?
- How do I convert a double into a string in C++?
- Split a string using C++11
- How do I iterate over the words of a string?
- How do I iterate over the words of a string?
- Returning an empty string : efficient way in c++
- C++ string to double conversion
- What is use of c_str function In c++
- What is uintptr_t data type
- What is the difference between const int*, const int * const, and int const *?
- C++ – No matching member function for call to ‘push_back’
- C++ Parsing input string to variables
- What does int & mean
- What is the difference between const int*, const int * const, and int const *?
- How do I tokenize a string in C++?
- Why use string::iterator rather than index?
- C++ deprecated conversion from string constant to ‘char*’
- Passing a 2D array to a C++ function
- identifier “string” undefined?
- Converting a vector
to string - How can I convert const char* to string and then back to char*?
- std::string formatting like sprintf
- Sorting Characters Of A C++ String
- basic_string::_M_construct null not valid after constructing subvector of strings
- Can’t resolve Error: indirection requires pointer operand (‘int’ invalid)
- How to return a string from a C++ function?
- What is the difference between isdigit() and isnumber()?
- Convert char* to string C++
- How to access the contents of a vector from a pointer to the vector in C++?
- printf with std::string?
- Read whole ASCII file into C++ std::string
- How to make an array with a dynamic size? General usage of dynamic arrays (maybe pointers too)?
- C++ String Variable Declaration
- What does int & mean
- Split a string into an array in C++
- C++: Expression must have a constant value when declaring array inside function
- splitting a string into an array in C++ without using vector
- Remove spaces from std::string in C++
- Delete 2D array C++
- Remove spaces from std::string in C++
- c++ convert string to hex
- How can I iterate through a string and also know the index (current position)?
- c++ parse int from string [duplicate]
- C++ Expression must have pointer-to-object type
- initial value of reference to non-const must be an lvalue
- Typedef function pointer?
- How to initialize a vector of pointers
- How to Convert a C++ String to Uppercase
- std::cin input with spaces?
- C++ Remove punctuation from String
- How to alphabetically sort strings?
- Hash function for a string
- How do I check if a C++ std::string starts with a certain string, and convert a substring to an int?
- Using C-string gives Warning: “Address of stack memory associated with local variable returned”
- Reference to non-static member function must be called
- Why use pointers?
- Why I cannot cout a string?
- How to print a string in C++
- std::string length() and size() member functions
- How to convert QString to int?
- What’s the difference between * and & in C?
- Which is faster C++ String length() or size()?
- How do I create a random alpha-numeric string in C++?
- error: switch quantity not an integer
- Reading a string from file c++
- How to change string into QString?
- Remove last character from C++ string
- Converting String to Cstring in C++
- c++ sizeof( string )
- C++ Array of pointers: delete or delete []?
- Warning: comparison of distinct pointer types
- ‘setprecision’ is not a member of ‘std’
- Initializing pointers in C++
- Difference between function arguments declared with & and * in C++
- Is C++ Array passed by reference or by pointer?
- enum to string in modern C++11 / C++14 / C++17 and future C++20
- set head to NULL (‘NULL’ : undeclared identifier)
- What is a `char*`?
- Converting bool to text in C++
- clearing a vector of pointers [duplicate]
- Array of Linked Lists C++
- Declaration is incompatible with type
- I’m getting the error “stoi is not a member of std” in myprogramminglab [duplicate]
- Differences between unique_ptr and shared_ptr