Jump to content


Check out our Community Blogs

The Midnighter

Member Since 25 Oct 2007
Offline Last Active Jan 07 2008 05:30 AM
-----

Posts I've Made

In Topic: Searching a file

27 November 2007 - 01:05 PM

I lied. It's all good now, check it out:

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

string line,charClass,str,dex,hp,lvl,wepID,exp;
char filein[55];
char fileout[55];
string charName;
size_t pos;
size_t comma;

int main()
{
	cout << "Enter your file name you want to search in (C:\\Blah.txt): ";
	cin >> filein;
	ifstream myfile(filein);

	if (!myfile.is_open()) { cout << "File could not be opened from: " << filein << "\n"; }
	else 
	{
		while(! myfile.eof())
		{
			getline(myfile,dex,',');
			getline(myfile,hp,',');
			getline(myfile,str,',');
			getline(myfile,exp,',');
			getline(myfile,charClass,',');
			cout << "Name: " << charClass << "\nHealth: " << hp << "\nStrength: " << str << "\nDexterity: " << dex << "\nExperience: " << exp << "\n";
		}
		myfile.close();
	}
	system("PAUSE");

	return EXIT_SUCCESS;
}

char.txt looks like:
50,5000,500,10000,Red-Tipped Dragon

Output looks like:
Enter your file name you want to search in (C:\Blah.txt): C:\char.txt
Name: Red-Tipped Dragon
Health: 5000
Strength: 500
Dexterity: 50
Experience: 10000
Press any key to continue . . .

In Topic: Displaying a text grid

25 November 2007 - 03:05 PM

Progress.

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
 
using namespace std;

#define GRST 2
 
char grid[3][3];
void _writeGrid(int flag);

int main()
{
	_writeGrid(GRST);
	system("PAUSE");
	return EXIT_SUCCESS;
}
 
void _writeGrid(int flag) {
    int i, j;
 
    if (flag == GRST) {
        for (i=0;i<3;i++) {
            for (j=0;j<3;j++) {
				cout << "|_|" << grid[i][j];
            }
            cout << endl << endl;
        }
    } 
}

Out puts like:

|_| |_| |_|

|_| |_| |_|

|_| |_| |_|

In Topic: Displaying a text grid

22 November 2007 - 12:03 PM

Why couldn't I use ASCII?
What would you suggest?

I want it to look something like:

Couldn't get underline to work with any sort of formatting, so imagine the boxes are closed in.


_____________________
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |

In Topic: C++ to HTML?

12 November 2007 - 12:14 PM

Alright, so I've got some code going here, and here's my problem:

I've got the file opening and closing, and I've got it reading lines, and I can output the file to the .html file, but it comes out in one line, and I'm not very sure on how to replace characters yet, here's my code so far:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;


int main()
{
	ifstream InputStream;
	ofstream OutputStream;
	string filein, fileout,HTMLSource;
	bool finished = false;	

	while(finished==false)
	{
		cout << "Enter file in: ";
		getline(cin,filein);
		if (filein == "") break;

		InputStream.open(filein.c_str());
		if (InputStream.fail())
		{
			cout << "Failure! File was unable to open. Check path / Filename / Extension. (C:\\Filein.cpp)";
		}
		else
		{
			cout << "Input open!\n";
		}

		cout << "Enter file out: ";
		getline(cin,fileout);
		if (fileout == "") break;

		OutputStream.open(fileout.c_str());
		if (OutputStream.fail())
		{
			cout << "Failure! File was unable to open. Check path / Filename / Extension. (C:\\Fileout.html)";
		}
		else
		{
			cout << "Output open!\n";
		}

		string next;
		InputStream.get(next);

		while (next == "<")
		{
			string file, tmp; 
			while (getline(InputStream, tmp)) 
				file += tmp + "\n";
			//OutputStream << file;
		}


		InputStream.close();
		cout << "Closed input.\n";
		OutputStream.close();
		cout << "Closed output.\n";


	} // End while TRUE

	system("PAUSE");
	return EXIT_SUCCESS;
}

In Topic: C++ to HTML?

06 November 2007 - 08:36 PM

In about 5 lines of PHP, you can probably open the file, replace all the special characters with their proper entity, and output [echo] the source [html].

There is also a great PHP class called GeSHi [thats what this forum uses for its syntax highlighting], you can set it up to read from files and highlight the syntax too with 20 or so lines of PHP.


Yeah.. I've been writing php for a few years now.

Any idea for C++ Anyone? xD

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download