I am a total noob in c++ programing. And i wanna learn it very bad:D.
So for anew task i have to write a program that reads data from text and than replace all vowels with some symbol. I know how to erad text from a file, but than i dont know how to tell the program to change all vowels with *. I dont know how to, when i read text from file, store this text in some string or what. Than i think i must do, that the programme compares vowels with every letter in the text, and when the vowel matches a letter it changes it to *. But i dont know how to put this in code:D
So if someone could help me i would be very happy:P
ifstream file("vowels.txt";
std::string stdstr; /*or*/ char cstr[80];
//then choose one
file >> stdstr;//reads one word
//or
getline(file, stdstr);//reads the whole line
//or
file >> cstr;
//or
file.getline(cstr, 80);//whole line (or at least 80 symbols)
it's good so far.
now, you know what code you need. you just have to decide where you need it.
before line 4? there cstr is undeclared so you can't operate on it.
on line 5? there cstr exists, but there is nothing in it yet (there is rubbish)
after on line 18? the program will never reach that.
line 14? on every cycle of the while loop a line is read and stored in cstr. new lines overwrite the old ones therefore you would only be able to change the last line after the loop has ended.
line 8? on the first cycle, line 9 will read a string. then on the second cycle line 8 will be able to change it. yay. though I wonder what will line 8 be changing on the first cycle? and will the last line be changed?
so, what line remains? you could just paste the code where you want and try it..
you know the code. I already wrote it. look at my first post. You combined it correctly in your 2nd post, just you have to use the other for loop here (though in many cases your life would be simpler if you used std::string, so you may want to get used to those at some point)
an I forgot about your other question the last time. the second part of the for( ; ; ) is a condition. when this condition is not met, the loop ends.
Hmm i will try something to do with this code tonight hope i will get it right...
Just 1 thing....
This code : file.getline(cstr,80); does it gets only 1 line from txt file? What if txt has more than 1 line in it ? Will it get the whole txt?
length() is a method of std::string.
as I said, for c-strings use for(int i = 0; cstr[i] != 0; i++)
you may also use for(int i = 0; i < strlen(cstr); i++) if you find that easier to understand.
other than that it should work. just remember to add some output :)
ok i change the for sentence with this1for(int i = 0; i < strlen(cstr); i++)
When i compile the code there are some errors, but i donnu why :D
`ifstream' undeclared (first use this function)
`;' before "file"
`file' undeclared (first use this function)
I think all of this is declared or am i missing something. And i also want to ask if i need to close this document somewhere? I open it with ifstream("wofels.txt"); Do i need to close it at the end ?
Tomorow i will look at output data so i save this in some txt files, but first i would like to run this code without errors:D