Archived

This topic is now archived and is closed to further replies.

text File reading

This topic is 5292 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve tried numerous methods to try and get this working, but it just doesn''t. I want to read text files, and convert the result into a LPSTR or something. I tried making a 4byte text file that says "Yay!" and load that up with a function I made. (that got changed and overwritten throughout time) and then write
if(lpString == "Yay!") //Do Something 
But alas, it doesn''t. Does anyone have anyknowledge or links for me? I don''t have a signature, sorry.

Share this post


Link to post
Share on other sites
Try using string:

#include <iostream>
#include <fstream>
#include <string>

int main()
{
    ...

    std::ifstream inFile("in_file.txt");
    if (inFile.fail())
    {
        // handle error
    }

    std::string word;
    while (!inFile.eof())
    {
        inFile >> word;

        if (word == "Yay!")
            std::cout << "Hmmm, I see that you are happy, Sir.\n";

        ...
    }

    ...

    inFile.close();

    ...

    return 0;
}


[ Google || Start Here || ACCU || MSDN || STL || GameCoding || BarrysWorld || E-Mail Me ]

Share this post


Link to post
Share on other sites
Ooh, I''m happier... , but I''ll give it a go. I can''t right now, but maybe in the next hour or so. Or later. Anyway, thanks for the help. MSDN wasn''t that helpful...

I don''t have a signature, sorry.

Share this post


Link to post
Share on other sites
quote:
Original post by Tooko
Ooh, I''m happier... , but I''ll give it a go. I can''t right now, but maybe in the next hour or so. Or later. Anyway, thanks for the help. MSDN wasn''t that helpful...

I don''t have a signature, sorry.


Of course MSDN wouldn''t help for this! If you use the strcmp, you would need a libC reference, if you do it the string way, you would need the STL programmers manual.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
strcmp() is in the MSDN. you would write it like this
if(!strcmp(lpString, "Yay!"
{
//lpString did equal Yay!
}
else
{
//lpString did not equal Yay!
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
strcmp() is in the MSDN. you would write it like this
if(!strcmp(lpString, "Yay!")
{
//lpString did equal Yay!
}
else
{
//lpString did not equal Yay!
}

Share this post


Link to post
Share on other sites