• 0

Using files to store data in C++


Question

Hey,

I'm still a beginner trying to get my basics right, so please have patience with me.

I'm trying to store values from the user into a file in the following way:

while(count<5)

{

cout<<"Enter values: ";

outData << value;

count++;

}

However I am getting a warning the "value" wasnt defined. Anyway can anybody help me with this ?

P.S. I am declaring the file streams correctly, using the correct header file etc.,

Thanks !

Link to comment
https://www.neowin.net/forum/topic/149219-using-files-to-store-data-in-c/
Share on other sites

13 answers to this question

Recommended Posts

  • 0

Looks to me that you are never reading in any data. Try this

int value;     // for numbers or
char value;  // for letters/charactors

while(count&lt;5)
{
cout&lt;&lt;"Enter values: ";
cin &gt;&gt; value;
outData &lt;&lt; value;
count++;
}

That may be what you are looking for

  • 0
  virtorio said:
Looks to me that you are never reading in any data. Try this

int value; ? ? // for numbers or
char value; ?// for letters/charactors

while(count&lt;5)
{
cout&lt;&lt;"Enter values: ";
cin &gt;&gt; value;
outData &lt;&lt; value;
count++;
}

That may be what you are looking for

Virtorio's code will wo(Y)(Y) Just make sure you only declare value on;) ;)

  • 0

I closed it and reopened it the following way:

outData.close(); //Closing the file.dat after writing values into it.

inData.open("file.dat //Reading values from file.dat

I dont know how to use the rewind function. I was also trying seekg but that is isnt working. I am doing something wrong with the syntax, i think.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.