Text Data issue

Pages: 12
May 22, 2013 at 7:16pm
closed account (NUj6URfi)
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
May 22, 2013 at 7:20pm
closed account (NUj6URfi)
Does anyone out there know how to?
May 22, 2013 at 7:39pm
closed account (NUj6URfi)
Please help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
May 22, 2013 at 7:43pm
some_file_stream << "hobbit";
May 22, 2013 at 7:46pm
closed account (NUj6URfi)
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
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 7:52pm
closed account (NUj6URfi)
I use that how?
May 22, 2013 at 8:01pm
closed account (NUj6URfi)
Please help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
May 22, 2013 at 8:07pm
closed account (NUj6URfi)
Not solved topic!!!
May 22, 2013 at 8:17pm
closed account (NUj6URfi)
Please help!!!!!!!!!!!!!!
May 22, 2013 at 8:19pm
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:27pm
closed account (NUj6URfi)
Sorry I am impatient.
May 22, 2013 at 8:56pm
closed account (NUj6URfi)
Help??
May 22, 2013 at 8:59pm
I showed you an example how to read a word from a text file.
May 22, 2013 at 9:01pm
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
closed account (NUj6URfi)
I want the program to go "this file has this text so function hobbit.
May 22, 2013 at 9:12pm
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
May 22, 2013 at 9:20pm
closed account (NUj6URfi)
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
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
May 22, 2013 at 11:30pm
closed account (NUj6URfi)
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?
Pages: 12