I need to turn the characters in a string that's generated from a data file into *'s and make it visible to the user.

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
	int numph;		//First number in .dat file saying how many worsd there are
	int wordnum;	//Number of which word in the list the program uses
	int ctr1=0;		//Counter for first loop
	string word, wordstar;	//Word that the user is trying to guess
	int money;		//Number of money

	srand(time(NULL));

	ifstream infile;
	infile.open("words.dat");
	infile>>numph;

	wordnum=rand()%numph+1;
	

	while(ctr1!=(wordnum+1))
	{
		getline(infile, word);
		ctr1++;
	}

As of right now, the code works fine and it gets a random word from my text file. What I want to do is take that word (let's say the word is hotdog) and print it to the scren as ****** or if it were hotdog bun ****** *** respecting spaces as they appear.

I have a start on this with

for (int n=0; n<=t.length()-1; n++)

Any suggestions?

for (int n=0; n<=t.length()-1; n++)
    t[n]='*'

Test for SPACE before executing the statement so you can skip over it.

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.