Tuesday, November 11, 2008

I'm a loser...

Not a very complicated program, but I still feel kinda proud as this will save some time for me to post photos on websites. So, here we go:


#include <iostream>
#include <fstream>
#include <string>

using namespace
std;

int
main () {
string filename, line, imgsrc = "<img src=\"", end = "\">";
cout << "NOTE: You must have the text file in the same folder as this executable!!" << endl;
cout << "What is the name of your file? (inlcuding the .txt)" <<endl;
cin >> filename;
ifstream fin (filename.c_str());//old C string style
ofstream fout("converted.txt");
if
(!fout) {
cout << "Cannot open output file." << endl;
return
1;
}

if
(fin.is_open())
{

while
(!fin.eof())
{

getline (fin,line);
//cout << line << endl;
line = imgsrc + line;//add the <img src = " part
if(line == imgsrc){
//ignores the blank lines, if there are any
}
else
{
line = line + end;//adds the "> part
fout << line << endl << endl;//add a space for convience
}
}

cout << "tags added" << endl;
fout.close();
fin.close();
}


else
cout << "Unable to open file" << endl;

system("PAUSE");
return
0;
}



and here is a photo of it:


Yea, so that was it. If you don't understand this, well, whatever. But if anyone would like to use the program, just send me an e-mail to davidnewtonphotog@gmail.com

No comments: