Any insight how to solve finding a const string fullName = "..."

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rafael Olarte
    New Member
    • Jan 2007
    • 14

    Any insight how to solve finding a const string fullName = "..."

    Dear Friends,

    I will really appreciate any assistance in this particular challenge. I am pretty much new with C++ (ISO/ANSI)

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    const string fullName =  " Franklin Delano Roosevelt" 
    
    int main( )
    
    {
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Hi. Love to help but I have no idea what your question is

    Comment

    • interview question
      New Member
      • Jan 2007
      • 1

      #3
      Originally posted by Rafael Olarte
      Dear Friends,

      I will really appreciate any assistance in this particular challenge. I am pretty much new with C++ (ISO/ANSI)

      #Iinclude <iostream>
      #include <string>

      using namespace std;

      const string fullName = " Franklin Delano Roosevelt"

      int main( )

      {
      Are you getting compilation error ? Why are you including <string> ? you can try using std::string

      Comment

      • Rafael Olarte
        New Member
        • Jan 2007
        • 14

        #4
        Originally posted by willakawill
        Hi. Love to help but I have no idea what your question is
        Thanks for your reply. For some reason, I have edited my question, but it did not up-date. Sorry.

        here is what I am trying to accomplish:

        #include <iostream>
        #include <string>

        using namespace std;

        const string name = "John Paul Jones";

        int main() {


        int spacePos = name.find(' ');

        string firstName = name.substr(0, spacePos);
        string middleName = name.substr(spa cePos + 1);



        cout << firstName + ' ' << middleName << endl;

        return 0;

        }

        My goal is to be able to show first any name that is type above the int "string const <name>= "..."

        As an example, I have firstname= John, middlename = Paul and lastname = Jones.

        However, the problem is that I really do not know how to go about this. So far, I have been able to obtain the first name correctly. When I request the middlename, it actually provides me both: middlename, and lastname.

        Thanks so much!!

        Comment

        • Rafael Olarte
          New Member
          • Jan 2007
          • 14

          #5
          Originally posted by interview question
          Are you getting compilation error ? Why are you including <string> ? you can try using std::string
          thanks for your reply.

          So far, I am not getting an error up to what I have accomplished. The issue I am having is that I really do not know how to make the three names show up on the screen correctly.

          I am supposed to be able to use any given names on the const string fullname = " ";

          and be able output the correct results no matter how long or short the names are.

          ei:

          I am trying to cout >> firstName >> middleName >> lastName >>


          This is the code I have so far:

          #include <iostream>
          #include <string>

          using namespace std;

          const string name = "John Paul Jones";

          int main() {


          int spacePos = name.find(' ');
          // int len = name.length();
          string firstName = name.substr(0, spacePos);
          string middleName = name.substr(spa cePos + 1);



          cout << firstName + ' ' << middleName << endl;

          return 0;

          }

          Thank you for your time!! and any input in resolving this challenge.

          Have a great day!

          Comment

          Working...