Text Data issue

Pages: 12
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
closed account (NUj6URfi)
Does anyone out there know how to?
closed account (NUj6URfi)
Please help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
some_file_stream << "hobbit";
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<<'
Let assume that you have a file with the word.

std::ifstream in( "MyFile.txt" );

std::string secreat;

if ( in >> secreat ) hobbit();
closed account (NUj6URfi)
I use that how?
closed account (NUj6URfi)
Please help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
closed account (NUj6URfi)
Not solved topic!!!
closed account (NUj6URfi)
Please help!!!!!!!!!!!!!!
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.
closed account (NUj6URfi)
Sorry I am impatient.
closed account (NUj6URfi)
Help??
I showed you an example how to read a word from a text file.
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?
closed account (NUj6URfi)
I want the program to go "this file has this text so function hobbit.
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
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.



Try to correct the errors yourself. For example change semicolon in this line to colon

"wizard" ) != std::istream_iterator<std:;string>() )
Last edited on
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