If your program runs on a different computer, it will look for "C://Users//My name//foo.txt" on their computer, failing to open the file if it doesn't exist. (So unless they have the same name as you, the above path would likely fail)
This is partially why full hardcoded pathnames are avoided. Instead you can use a relative path (just "foo.txt") and that will look in the current directory (typically the same directory as the exe, but when running from an IDE it might be the project directory instead).
Or you can prompt the user to supply the path/filename and leave it up to them to get it right.
Instead you can use a relative path (just "foo.txt") and that will look in the current directory (typically the same directory as the exe, but when running from an IDE it might be the project directory instead).