Computing.Net > Forums > Programming > C++ String Project?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C++ String Project?

Reply to Message Icon

Name: Haydogsup
Date: October 12, 2005 at 18:09:16 Pacific
OS: Win XP
CPU/Ram: N/A
Comment:

I was assigned a project that required me to write a program that could ask a user for the name of a data file. This filed would contain a list of students in a class. The names are listed, one per line, in the following format:

lastName firstName middleInitial

Then, I have to take the firstName and lastName and concatenate them and add ".dat". Using the new firstNamelastName.dat format it would open the corresponding student's data file, read in their test scores, and then calculate the average.


None of my attempts at starting have been fruitful at all. :(



Sponsored Link
Ads by Google

Response Number 1
Name: Gargamel
Date: October 12, 2005 at 19:06:58 Pacific
Reply:

Hi Josh.

If you describe your attempts and maybe add some source code it would be possible to help you trace the problems...


0

Response Number 2
Name: SteveWalsh
Date: October 21, 2005 at 12:44:46 Pacific
Reply:

Simple, simple

first you need a file stream

#include <fstream> //if 6.0 use fstream.h
using namespace std;

int main() //i'm assuming this isn't a GUI
{

char stringfirstname[80]; //First
char stringlastname[80]; //Last
char stringmiddlename[80]; //middle

ifstream getnames("file.txt"); //creates the file stream
while (!getnames.eof())
{
getnames >> stringfirstname; //get first name
getnames >> stringlastname; // get last name
getnames >> stringmiddlename; // middle name

// do what ever you need to do here

}

}

hope that helps you. I'm not going to write the whole program for you (otherwise how are you going to learn?) remember that besides importing strings similar to cout cin, you can also you the get() and write() (not sure if that is right)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C++ String Project?

c++ string trouble pls help www.computing.net/answers/programming/c-string-trouble-pls-help/6206.html

c++ string manipulation question www.computing.net/answers/programming/c-string-manipulation-question/11524.html

c game project www.computing.net/answers/programming/c-game-project/17943.html