Creating a data file in C++

Trying to create a file to hold data using c++

Page 1 of 1

2 Replies - 6915 Views - Last Post: 20 November 2008 - 10:49 PM Rate Topic: -----

#1 mat.roscoe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 26-November 07

Creating a data file in C++

Posted 19 November 2008 - 10:59 AM

[color=#000099]

Hello,

I am looking for some quick help with a fairly simple idea in C++ or in C. I am trying to create a data file that a program will access and what i would like to do is when the program starts up the user will provide their name and this will be used to "create" their data file that will contain all of the information about this one user. I have no issues getting the users name and storing that as a string value. my problem is taking this and turning it into a usable file name. This is the basic outline of what i have tried to do and from what i know in both Java and C this should have worked but is not working.

Example: user inputs their name as "BOB" a file called BOB.miab will be created within the current working directory

	   std::string				 FirstName;
	std::string		LastName; 
	std::string		FileName; 
	std::string		FileExtension;

	FileExtension = ".miab";

	FileName = Name + FileExtenstion;

	NameFile.open( FileName );
	NameFile << FirstName << " ";
	NameFile << LastName; 
	NameFile.close(); 




Any help at all would be greatly appreciated and thanks for looking :)

[size=4]

Is This A Good Question/Topic? 0
  • +

Replies To: Creating a data file in C++

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Creating a data file in C++

Posted 19 November 2008 - 05:29 PM

View Postmat.roscoe, on 19 Nov, 2008 - 09:59 AM, said:

	std::string		FirstName;
	std::string		LastName; 
	std::string		FileName; 
	std::string		FileExtension;

	FileExtension = ".miab";

	FileName = Name + FileExtenstion;

	NameFile.open( FileName );
	NameFile << FirstName << " ";
	NameFile << LastName; 
	NameFile.close(); 


FileName = Name + FileExtenstion; Where is Name defined? B)

This post has been edited by n8wxs: 19 November 2008 - 05:31 PM

Was This Post Helpful? 0
  • +
  • -

#3 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Creating a data file in C++

Posted 20 November 2008 - 10:49 PM

Without getting too deep this line is an immediate problem
FileName = Name + FileExtenstion;



1 - Where does the variable 'Name' come from?
Did you mean 'FirstName' (which would more normally be written firstName)?

2 - Did you mean 'FileExtension' when you wrote 'FileExtenstion'
(again, variables are more normally written with a lowercase first character e.g. 'fileExtension')

This might help with your deeper problems.
http://www.cplusplus...rial/files.html

This post has been edited by janotte: 20 November 2008 - 10:52 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1