May 22, 2013 at 7:16pm UTC
Hi. I would like to be able to record a word in a text file and have the program see but not print that word. Then I would like it to say
1 2
if (text == hobbit)
hobbit() ;
I did the functions and all the stuff about the .txt doc. But the if statement doesn't work. Does anyone know how to do an if statement to look at .txt text?
Last edited on May 22, 2013 at 7:17pm UTC
May 22, 2013 at 7:20pm UTC
Does anyone out there know how to?
May 22, 2013 at 7:39pm UTC
Please help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
May 22, 2013 at 7:43pm UTC
some_file_stream << "hobbit";
May 22, 2013 at 7:46pm UTC
if ("Save data.txt" << "hobbit") {
hobbit() ; }
It doesn't work. Please help!!!! It says
invalid operands of types `const char[14]' and `const char[7]' to binary `operator<<'
May 22, 2013 at 7:51pm UTC
Let assume that you have a file with the word.
std::ifstream in( "MyFile.txt" );
std::string secreat;
if ( in >> secreat ) hobbit();
May 22, 2013 at 8:01pm UTC
Please help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
May 22, 2013 at 8:17pm UTC
Please help!!!!!!!!!!!!!!
May 22, 2013 at 8:19pm UTC
I think it would be reasonable to bump the thread once in 24 hours. Four times in an hour is more like misuse of the forum in my opinion.
May 22, 2013 at 8:59pm UTC
I showed you an example how to read a word from a text file.
May 22, 2013 at 9:01pm UTC
Good luck getting help with all your spam. You bumped 8 times in one topic within 2 hours and most of them are withing like a 10 minute period...Also I find it unclear what you are waning to do are you trying to input only if it equal to a word? or compare the result string to a word?
May 22, 2013 at 9:06pm UTC
I want the program to go "this file has this text so function hobbit.
May 22, 2013 at 9:12pm UTC
Is the text is a single word?
You can do this the following way
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <iterator>
...
std::ifstream in( "MyFile.txt" );
if ( std:: find( std::istream_iterator<std::string>( in ),
std::istream_iterator<std::string>(),
"hobbit" ) != std::istream_iterator<std:;string>() )
{
hobbit();
}
Last edited on May 22, 2013 at 9:15pm UTC
May 22, 2013 at 9:20pm UTC
That gives me quite a few errors look.
if ( std:: find( std::istream_iterator<std::string>( in ),
std::istream_iterator<std::string>(),
"wizard" ) != std::istream_iterator<std:;string>() )
{
wizard();
}
Try compiling that.
May 22, 2013 at 9:35pm UTC
Try to correct the errors yourself. For example change semicolon in this line to colon
"wizard" ) != std::istream_iterator<std:;string>() )
Last edited on May 22, 2013 at 9:36pm UTC
May 22, 2013 at 11:30pm UTC
I never learned std and used an easier way. The other way doesn't cover this. Can you please just give me the correct code?