Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Reading from .txt file

Author
Message
Manuel v2
13
Years of Service
User Offline
Joined: 7th May 2011
Location:
Posted: 30th May 2011 01:55
How to read a string from a text file?

This does not work, but the file is open.


I do not quite understeand the concept and uses of pointers, I guess that is what is messed up here.

My goal is to make Dark GDK as a visualization platform from another project. The main project will be sending in strings and arrays for the Dark GKD to display.

Can anyone help me read this "Hello"?
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 30th May 2011 06:44
This isn't the Dark GDK area... you want this area:

http://forum.thegamecreators.com/?m=forum_read&i=22

I don't know about Dark GDK but if it's just a standard .txt file you shouldn't need to use pointers at all.

Manuel v2
13
Years of Service
User Offline
Joined: 7th May 2011
Location:
Posted: 30th May 2011 20:44
It's such a simple question I though the newcomers area would be the correct one.
Anyway, I'v got no way to change it now.

"Reading a text file. How?"
Manuel v2
13
Years of Service
User Offline
Joined: 7th May 2011
Location:
Posted: 30th May 2011 21:39


Can someone help me please.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 30th May 2011 23:38 Edited at: 30th May 2011 23:46
I imagine that if this is reading a float:


Then doing this would be reading a string:


But again this is the Darkbasic Pro area so we do it like this:


Check out this thread in the (surprise, surprise) Dark GDK area:
http://forum.thegamecreators.com/?m=forum_view&t=166632&b=22

Manuel v2
13
Years of Service
User Offline
Joined: 7th May 2011
Location:
Posted: 31st May 2011 01:21
Yeaah well sorry for the unnecessary topic...

That link was enought, I'll just use the normal iostream but I did not know how to change the debug options to multithreaded:

http://forum.thegamecreators.com/?m=forum_view&t=185166&b=22

Anyways, I can read and write files great now!
Just one more thing: how to read and write files outsite the project's folder?

I want to use .txt files to make a bridge betewn 2 projects (or more), so I need the In/Out .txt files to be inside say My Documents while the two projects are in separated folders.

I tryed "C:\Users\user\Documents\Test.txt" but it doesent open the file...

Btw: is it "safe" to use these files has I want to? I need to write and read olny a couple of vars but some 30 times per second.

What should I do?


http://www.cplusplus.com/reference/iostream/iostream/ - They dont talk about outside files.

[/code]#include "DarkGDK.h"
#include <iostream>
#include <fstream>

using namespace std;


void DarkGDK ( void )
{
char * buffer;

ifstream File;
File.open ("Test.txt", ios::binary );

buffer = new char [10];
File >> buffer;

File.close();
dbText(400,0,buffer);
delete[] buffer;
while(LoopGDK ( )){
dbSync();

if ( dbEscapeKey ( ) ){
break;
}
}
return;
}[code]
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 1st Jun 2011 06:03
Quote: "I want to use .txt files to make a bridge betewn 2 projects (or more), so I need the In/Out .txt files to be inside say My Documents while the two projects are in separated folders.
"


Are these separate programs that you've made or are you trying to share data between a program you've made and one you didn't?

Quote: "I tryed "C:\Users\user\Documents\Test.txt" but it doesent open the file...

Btw: is it "safe" to use these files has I want to? I need to write and read olny a couple of vars but some 30 times per second."


Generally using the documents directory is safe but it's not that easy because most Windows use the actual user name instead of the second "user" in your attempt. It's best to grab the documents directory with the MYDOCDIR$() command (which is probably DBMYDOCDIR() in Dark GDK) so you don't have to know the persons user name to access that directory.

Mistrel
Retired Moderator
19
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 1st Jun 2011 08:48
Don't use ios::binary unless you're actually reading binary data. Otherwise you'll end up reading the end of line characters as well.

Login to post a reply

Server time is: 2024-11-22 22:23:31
Your offset time is: 2024-11-22 22:23:31