Will this program compile on Windows? I need to turn in a project that compiles on Windows (specifically, Visual C++) for a class I'm taking. However, I am a Mac/UNIX user (please don't shoot me!) and I have been compiling and running programs in Terminal since I started learning to program two years ago, never using Windows to do so. I don't have a working Windows computer at my house, and I have no idea how to compile my project on a school computer. The program runs fine on my Intel-based Mac, but I know there are differences when you try to run it on a Windows computer.
The program reads in a text file containing a poem to an array. You can then delete words starting with a specific letter and print the array. At the end, it will make a text file containing what remains in the array.
Will someone please compile and run this program on their Windows computer so I can be sure that my instructor will be able to run it?
Please make a selection:
a) Read a text file
b) Remove words starting with letter
c) Print words to console
d) Quit
-> a
Enter a filename to open: sample.txt
Loaded file and read 15 words.
Please make a selection:
a) Read a text file
b) Remove words starting with letter
c) Print words to console
d) Quit
-> c
so> muchα♥> depends uponá♥> a♥> red wheel♥> barrow> glazed> withα☻> rain└☻> wate
r☻> beside> the white☻>
This is because strlen returns length of a string without the null character.
1 2 3 4 5 6 7 8 9 10 11 12 13
Word::Word(constchar* word)
{
len = strlen(word)+1; // length of the string + 1 null ('\0') character
ptr = newchar[len];
memcpy(ptr, word, len);
}
Word::~Word()
{
delete[] ptr; // free unused memory
ptr = NULL;
len = 0;
}
You also need to #include <cstring> instead of <string> in word.cpp, and remove usingnamespace std; from word.h