Results 1 to 4 of 4

Thread: Reading and Writing

  1. #1
    Member
    Join Date
    Feb 2003
    Posts
    78

    Reading and Writing

    Ok, Again with my lyrics database. I have yet to actually start this project, because I am still playing around with different ways to to store the lyrics. But I am trying to play with creating a text file and put the lyrics in there and then everytime you run the program, it will just read the text into the approiate variables. Well, I havent quite got that far into this. ..

    Code:
    //Test
    #include<iostream>
    #include<fstream>
    using namespace std;
    
    int main()
    {
        char fileName[80] = "D:\Junk\C++\Text.txt";
        char buffer[256];
        
        ofstream fout(fileName);
        fout<<"Hello...\n";
        fout.close();
        
        ifstream fin(fileName);
        char ch;
        while(fin.get(ch))
        {
            cout << ch;    
        }
        system("PAUSE");
        return 0;
    }
    When I first ran this program, I did not write anything to the file, I wanted to just read it. Well, I couldnt get it to work. Well, I have a C++ book right in from of me and just copied a section of the code. And now it works. Problem, Instead of writing and reading to the text file I have created in D:\Junk\C++, the program creates a file in my C++ folder called "JunkC++Text". I am wondering why it does it, and if there is a way I could get the program to read/write to files that are not in the same folder as the compiler its self. Any help is great. Thanks in advance.

    -Ep
    01001001001000000100110001101111011101100110010100100000010000100110010101110100011101000111100100100001

  2. #2
    your problem is your
    Code:
    char fileName[80] = "D:\Junk\C++\Text.txt";
    it should be:

    Code:
    char fileName[80] = "D:\\Junk\\C++\\Text.txt";
    this is because the '\' is an escape sign, just like you put in '\n' to have a newline, you also have to put in '\\'to print out a single backslash.

  3. #3
    Member
    Join Date
    Feb 2003
    Posts
    78
    Thanks for clearing that up for me. It has been driving me wild for some time now. I thought no one was going ot answer my question, and I was sure that someone here at the AO community knew the answer. Again, thanks for the help.
    Also, while viewing thes threads, I noticed both AGI and winsock. I have no idea what these are, and I was wondering if anyone could provide a general view of what they are. Or how they are used. Im in no big hurry to study it or nothing, so im going to do any research on it (no google ). Thanks.

    -Ep
    01001001001000000100110001101111011101100110010100100000010000100110010101110100011101000111100100100001

  4. #4
    i think you mean API instead of AGI. well API and winsock are both functions written for windows that you can use fro windows programming. winsock is the windows version of socketprogramming (network connections) and an API could be just about anything, from a function to get the current working directory to a function to see which processes are running.

    here is an example of the GetAsynKeyState Function, you can find a lot more when browsing the libraries on www.msdn.com.

    hope this helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •