Use xargs with -I
cat hosts.txt | xargs -I %REPL ssh user@%REPL
-I defines a "replacement-string", in this case "%REPL" (but you can set it to what you like).
Then that specific string will be will be replaced in the command, with each line from input.
Another way i like, is using printf
echo -e "host1.com\nhost2.com" | xargs -n1 printf "ssh user@%s -p 999\n"
This is especially great, if you wanted to use more lines in the same command.. Imagine that you have a file with username on line 1 and hostname on line 2. You could simply do:
xargs -n2 printf "ssh %s@%s -p 999\n" < user_and_host.txt
Passwords
All this, assumes you are using SSH keys because, by design, the openssh client will not let you "script" passwords.
If you want to script using password authentication, there are tons of hints and methods (someone will yell "expect" any second now). But i did them all at some point or another, and they bring eternal pain and indigestion.
Its not worth it, scripting this yourself. Have a look at my favorite tool for this:
This will let you pretty much do what you need. Give it username, password, one or more commands to run + a bunch of hosts/ip's. When its done, you'll have a nice CSV-file with the result of every command, ordered by its host.