Hi, there im a new member, I have a few questions. i am having a problem i am trying tp find words that are related together by one word for example "dous" Tremendous,stupendous ect... I have my code working so that it goes through my text file and picks out all of the dous in the file, but how do i get the CMD to not only show "dous" when it is found, but the whole word" im a bit confused :-/.

here is my code:

#include<iostream>
#include<fstream>
#include<string>
using namespace std;

int main ()
{
	char* search = "dous";
	int offset;
	string TEXT;
	ifstream in_stream;
	in_stream.open("words.txt");
	if(in_stream.fail())
	{
		cout<<"File will not open, file possible dont exist or is corrupted"<<endl;
		exit(1);
	}
if( in_stream.is_open())
{
	while(!in_stream.eof())
	{
		getline(in_stream,TEXT);
		if ((offset = TEXT.find(search, 0)) != string::npos) 
		{ 
		cout << "found " << search << endl;
		}
	}
}
system("pause");
in_stream.close();
}

Recommended Answers

All 2 Replies

line 25 is using the wrong variable. display TEXT, not search.

Thx Man!, I knew it was something easy that i just needed to switch

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.