recall

This is a discussion on recall within the C++ Programming forums, part of the General Programming Boards category; hay, does anyone out there know how to pull info out of a .txt and insert it into a program? ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    4

    Question recall

    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

  2. #2
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    goto the tutorial and look at the section about ifstream and ofstream

  3. #3
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Like writing and reading to files?

    Here is some sample code:
    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;
    }
    That was really simpe, but I hope it kind of helps. Maybe check the FAQ?
    If you ever need a hug, just ask.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Absence of Visual Recall
    By Davros in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-24-2002, 01:27 PM
  2. Pixel Shaders.
    By Cheeze-It in forum Game Programming
    Replies: 1
    Last Post: 05-21-2002, 01:16 AM
  3. Replies: 17
    Last Post: 04-09-2002, 04:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21