hay, does anyone out there know how to pull info out of a .txt and insert it into a program? I have tried to read a since integer from a .txt and then make that equal a variable in my program ,but it never works... any ideas? thanks
Printable View
hay, does anyone out there know how to pull info out of a .txt and insert it into a program? I have tried to read a since integer from a .txt and then make that equal a variable in my program ,but it never works... any ideas? thanks
goto the tutorial and look at the section about ifstream and ofstream
Like writing and reading to files?
Here is some sample code:
That was really simpe, but I hope it kind of helps. Maybe check the FAQ?Code:#include <fstream> // File stream, you need this
#include <iostream>
using namespace std;
int main()
{
fstream file("somefile.txt", ios::out | ios::binary); // Opened somfile.txt for output mode and binary mode for write function
int stuff;
cout << "Enter stuff: ";
cin >> stuff;
file.write((char*)stuff,sizeof(stuff)); // write to the file
file.close(); // Close the file
return 0;
}