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.
text File reading
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
quote:Original post by Tookoif(lpString == "Yay!") //Do Something
You can''t compare strings(character arrays) this way. You have to use strcmp()
Try using
[ Google || Start Here || ACCU || MSDN || STL || GameCoding || BarrysWorld || E-Mail Me ]
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 ]
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.
I don''t have a signature, sorry.
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.
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!
}
if(!strcmp(lpString, "Yay!"
{
//lpString did equal Yay!
}
else
{
//lpString did not equal Yay!
}
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!
}
if(!strcmp(lpString, "Yay!")
{
//lpString did equal Yay!
}
else
{
//lpString did not equal Yay!
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement