• 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.
  • Posts

    • How is that going to work in companies with mixed PCs? Some can and some cannot upgrade to Windows-11. Most companies are not wealthy as Microsoft and afford to replace their entire collections of PCs with one that can run WIndows-11.
    • I mean... Exchange 2010 went out of support in 2020, so... eh. "Stern"? I'm not really getting that vibe. It's more of a "FYI" those those few who still use those versions; and I think 3rd party migration tools will work at least until Exchange Web Services (EWS) are turned off a year later (October 2026)...
    • OneNote is finally getting two highly requested features by Usama Jawad A few days ago, we learned that Excel is getting a highly requested PivotTable feature in the form of auto-refresh for this particular component. It seems like the company is looking to grant even more wishes as it has revealed that a couple more highly anticipated capabilities are coming to OneNote too. The first of these enhancements is the ability to merge cells in a OneNote table, just like you can do in Excel. This grouping can be both horizontal and vertical, and the content should align accordingly. There's not much else to say about this, it does exactly what it says on the tin. That said, it is important to note that Insiders have the ability to display merged cells across all OneNote platforms, but the ability to actually create merged cells is just available on Windows, Mac, and iPad for now. iPhone, Android, and web support are planned for a later date. Next, we have a quality-of-life (QoL) improvement in the form of the paste text only shortcut, also known as Paste Without Formatting. On Windows, this shortcut is Ctrl + Shift + V, while for Mac, it is Cmd + Shift + V. This is similar to other Microsoft 365 applications like Word and Teams, and the hope is that it will help keep content consistent and clean in terms of fonts, colors, and styling. Another way to trigger this behavior is the right-click context menu > Paste Text Only, as well as the Home > Paste > Paste Options > Keep Text Only toolbar. It is important to note that the pasted text will adopt the formatting of your OneNote target, not the original source. Also, this feature is currently available for Insiders on Windows, Mac, and the web only. That said, if either of the two capabilities is not visible to you right now despite meeting the minimum criteria mentioned here, it might be due to the staggered nature of the rollout.
  • Recent Achievements

    • Week One Done
      NeoWeen earned a badge
      Week One Done
    • One Month Later
      BA the Curmudgeon earned a badge
      One Month Later
    • First Post
      Doreen768 earned a badge
      First Post
    • One Month Later
      James_kobe earned a badge
      One Month Later
    • Week One Done
      James_kobe earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      660
    2. 2
      ATLien_0
      257
    3. 3
      Xenon
      164
    4. 4
      neufuse
      145
    5. 5
      +FloatingFatMan
      111
  • Tell a friend

    Love Neowin? Tell a friend!