I need help with this project

Posts 1–8 of 8 · Page 1 of 1
I need help with this project
I need help finding out how to read a txt file and turning it to a char.

I tried everything and i cant get it so please help

thanks
Quote Originally Posted by killer121561 View Post
I need help finding out how to read a txt file and turning it to a char.

I tried everything and i cant get it so please help

thanks
You just want to read the first ASCII character in a text file?
Code:
#include <fstream>
using namespace std;

char getfirstcharfromfile()
{
	ifstream thefilestream;
	thefilestream.open ("thefilename.txt");
	char *output;
	thefilestream >> output;
	return output[0];
}
Quote Originally Posted by yodaliketaco View Post
Code:
#include <fstream>
using namespace std;

char getfirstcharfromfile()
{
	ifstream thefilestream;
	thefilestream.open ("thefilename.txt");
	char *output;
	thefilestream >> output;
	return output[0];
}
I should correct myself. I was a little tired when I wrote this.

Code:
#include <fstream>
using namespace std;

char getfirstcharfromfile()
{
	ifstream thefilestream("thefilename.txt");
        char out = thefilestream.get();
        thefilestream.close();
	return out;
}
Code:
ifstream f;
f.open("freedompeace.txt");
f >> buf;
thanks every one i needed that
Code:
/* Make sure you have all of them
#include <d3d9.h>
#include <d3dx9.h>
#include <d3dx9core.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h> 
#include <string>
//#include <time.h>
#include <vector>
#include <windows.h>
#include <Winuser.h> */
using namespace std;
void DrawFileText( LPDIRECT3DDEVICE9 pDevice, const char *dir, D3DCOLOR TextColor, float x, float y )
{
	if( !pDevice )
		return;

	char txt[255];
	std::ifstream inFile( dir );
    if ( !inFile )
    {
		this->PrintText( x, y, TextColor, "While opening a file an error was encountered!" );
	}
	inFile.getline( txt, 255 );
	std::cout<<txt;
	this->PrintText( x, y, TextColor, txt );
}
Posts 1–8 of 8 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us