string full name

Hi im really new to c++. Im trying to finish a program.

Write a C++ program that takes a string containing a full name, and outputs each part of the name separately. The name should be in the form of first, middle, and last name separated from each other by a single space. For example, if the name string contains

“John Jacob Schmidt”

then the program would output:

First name: John
Middle name: Jacob
Last name: Schmidt

After you have completed this output the length of each name.


And this is what i have so far.

// Darlene Gail Espiritu
// Name.cpp

#include <iostream>
#include <string>

using namespace std;

int main()
{
string firstName;
string middleName;
string lastName;
string fullName;
first name = "Darlene"; // First Name
cout << firstname.lenght() << endl; // Prints 7
middleName = "Gail"; // Middle Name
cout << middleName.lenght() << endl; // Prints 4
lastName = "Espiritu"; // Last Name
cout << lastName.lenght() << endl; // Prints 8
fullName = firstName + middleName + lastName; // Full Name
cout << fullName.lenght() << endl; // Prints 22

return 0;
}


Please help me find out what's wrong. Thanks

D.G
It looks like you are not doing what you are asked to do.

Let me start the program for you:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <string>

using namespace std;

int main() {
    string fullName = "John Jacob Jingleheimerschmidt";
    string firstName; // ... you fill this in
    string middleName;  // ... ditto
    string lastName;   // ... ditto
    cout << "length of first name = " << firstName.length() << endl;
    cout << "length of middle name = " << middleName.length() << endl;
    cout << "length of last name = " << lastName.length() << endl;
};


There are many ways to accomplish the missing part. I don't know what method you are expected to use.


Yeah im not very good in programming :( im really having a hard time with it. anyway with the length of the names, do i need i put a numerical value? She did not specify what method but would you give me an example please?
Well, I don't know how she wants it done.

string has a lot of methods on it that can make this program trivial, but she might not want you to use them. Alternatively, you can write loops to search for spaces.

An example of the latter:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <string>

using namespace std;

int main() {
  string msg = "Hello world!";
  string word;

  for( int index = 0; index < msg.length(); ++index )
      if( msg[ index ] != ' ' )
           word += msg[ index ];
      else break;

  cout << word;
}



Try running the above program and see what it does.

When i try to run the program a box pops out and says this Please specify the name of the executable file to be used for the debug session. And I don't know what to do again.
Did you completely compile and link the program?
yah it's all fine now. thanks!
hi i have this project and i need help with it, maybe someone can help me. please?
im really new and really confused.

"You're working for a company that's building an email list from files of mail messages. They would like you to write a program that reads a file called mail.dat, and that outputs every string containing the @ sign to file addresses.dat. For the purpose of this project, a string is defined as it is by the C++ stream reader-a contiguous sequence of non-whitespace characters.
Given the data:

From: sharon@marzipan.edu
Date: Wed, 13 Aug 2003 17:12:33 EDT
Subject: Re: hi
To: john@meringue.com

John,

Dave's email is dave_smith@icing.org

ttyl,

sharon

Then the program would output on file addresses.dat:

sharon@marzipan.edu
john@meringue.com
dave_smith@icing.org.

Use meaningful variable names, proper indentation, and appropriate comments. Thoroughly test the program using your own data sets.


and this is what i have so far..and it's not working. im not really good with c++ so if someone can tell me what i am doing wrong it'll be great. thanks

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{

ifstream inFile;
ofstream outFile;
string tempString;


inFile.open("mail.dat");
outFile.open("addresses.dat");

while(inFile)
{
inFile>>tempString;
if(tempString.find('@')!=string::npos)
outFile<<tempString;

}

inFile.close();
outFile.close();
return 0;
}

what's the error? what's going wrong?
Apparently the program is correct...
let us know what's the problem...
This one's just a small play around with find and substring methods dude...
don't worry...
#include<iostream>
#include<string>
#include<fstream>
using namespace std;

void main()
{
ifstream inFile("C:\\emails.txt");

if(inFile.is_open())
{
cout << "File opened succesfully..." << endl;
}

std::string strIn = "";

while(!inFile.eof())
{
inFile >> strIn;

if(strIn.find("@", 0) != string::npos)
cout << strIn << endl;
}

inFile.close();
}

// above code was tested with following text file named emails.txt
/*
From: abcd@hotmail.com
To: pingazed@ymail.com
Subject: Important EMail ID

Hi bro, here's the contact details that you asked for.

Cell: 8822119922
email: zakoota@gmail.com

cheers,
bigM
*/
// snapshot of the output
// http://img55.imageshack.us/img55/6828/emailidextractorsnapsho.jpg
Topic archived. No new replies allowed.