jonnin wrote: |
---|
you can write the output to a web page (which can be a flat text file, as browsers will display those) |
suyashsing234 wrote: |
---|
how do i do it using website?
i want to put it on my pendrive so that my teacher can see my program but my school has all kinds of operating systems and can't tell her to use only windows. |
I’m just answering you about your first question, since I think you’ve already got plenty of explanation about the second.
(Just to contradict myself: about your second question... Are you really the only Windows user in your class?)
As jonnin explained, html file are no more than plain text files which happen to contain both text (for the reader) and instructions (for the browser) for displaying that text. The trick is if browsers can’t find any instructions for them, they display the text more or less as it is.
As a result, if you create a text file and you set its extension as ‘.html’, you can open it with a browser and read its content.
The following code creates a file named "suyashsing234.html" where’s written "Hi, I've successful created an HTML file!". If you double click on it, your default browser should open it and correctly show its content, regardless of your operative system.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <fstream>
#include <iostream>
#include <limits>
void waitForEnter();
int main()
{
std::ofstream myout("suyashsing234.html");
myout << "Hi, I've successful created an HTML file!\n";
std::cout << "Please find \"suyashsing234.html\".\n";
myout.close();
waitForEnter();
return 0;
}
void waitForEnter()
{
std::cout << "\nPress ENTER to continue...\n";
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
|
Granted it’s a great solution for those who need to write in English and English only, it’s got some limits. All these technologies have been mainly developed in USA and their developers only took into account what’s there on an English keyboard. If you need to display some characters that are not in the English alphabet, I’m afraid things won’t be so easy.
Possible solutions are:
1) Use only English alphabet and explain your teacher you couldn’t find a better solution.
I may appreciate that, if you’re native speaker of one of those thousands of languages that don’t come from the Latin alphabet, this sounds a terrible solution.
2) use html entities.
HTML entities are short ‘aliases’ for those characters which don’t appear in the English alphabet.
For example, if you want to write the German letter ß (in English: “SZ ligature”), you can write “ß” and your browser will display it correctly.
Again, if you needed to apply this method to all characters, it would be a nightmare.
3) Create you text file as utf-8 with BOM.
Modern browsers can display correctly those file in any languages they are written (but I personally don’t include Apple Safari in the directory of modern browsers). This is probably the best solution if your language doesn’t share characters with the English alphabet.
I’ve never created an utf-8 with BOM file, but it doesn’t look so hard. Anyway, this forum will be still there to ask for help :-)