Jump to content
  • Advertisement
Sign in to follow this  
olgolas

How do I make my programs work on other pc?

This topic is 3815 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I got a couple of questions, and search did not show up anything specific. 1. How can I make my console programs work on other pc's without installing a whole bunch of crap? Like .net and stuff? Is there any way at all? I build the programs in mvs 2008 (.net 3.5). Just simple text programs, built on c++, no extra libraries whatsoever, only iostream and using namespace std. Thanks, I was using debug version, will try build one now. 2. I want my program (text rpg) to look up for the map in map file. What is the best way to do that? Simple one? What I tried is to make "map" class, make the program look up for the class members in file, insert them there and ouput.

#include <library.h>

class map
{
public:
	char description[20];
	char creature[10];
};

bool map_render()
{

ifstream b_file ("map.txt");
b_file>> map::description;
cout<<map::description;
system("pause");
}

return true;
}

But it wont work, it says error C2597: illegal reference to non-static member 'map::description' error C2597: illegal reference to non-static member 'map::description' [Edited by - olgolas on January 10, 2008 1:52:15 PM]

Share this post


Link to post
Share on other sites
Advertisement
By default a VC++ project will link to the DLL version of the CRT library. Apps built like this require that the CRT Redistributable is installed on the running PC. Try setting your project to link to the static runtime, in project settings->C++->code generation.

Share this post


Link to post
Share on other sites
I found a way to read from file, using this:


#include <library.h>

bool map_render()
{

char description[15];

ifstream b_file ("map.txt");
b_file>> description;
cout<<"You enter the room. "<<description;


return true;
}




Here comes the question. How do I read not only the first word in file, but the whole description? I didnt find anything suitable in ifstream docs.
For example if I want to read the room description, monsters in it, and objects in it. So for example my map file looks like:

room description ........... monsters in room........ objects in room....

Is there a way to adress them in specific way so the program knows where to get data?

Share this post


Link to post
Share on other sites
This will solve the issues.
The map_render function will read a whole line from file into description, the map_render2 function will do the same but split the line into two items separated by :


#include <iostream>
#include <fstream> // ifstream
#include <string>
#include <sstream> // stringstream
#include <cstdlib> // system

class map
{
public:
char description[128]; // 128 bytes should be enough for this demo
char creature[128];
};

bool map_render()
{
map theMap; // working map object

std::ifstream b_file ("map.txt");
b_file.getline(theMap.description, sizeof(theMap.description)); // read the first string from file
std::cout << theMap.description << std::endl;

return true;
}

bool map_render2()
{
map theMap; // working map object
std::string line; // working string

std::ifstream b_file ("map.txt");
getline(b_file, line); // read the first string from file
std::stringstream ss(line); // fill a stringstream with the line so we can parse it
ss.getline(theMap.description, sizeof(theMap.description), ':'); // extract the first item from the line up to :
ss.getline(theMap.creature, sizeof(theMap.creature)); // extract the second item from the line up to newline (\n)
std::cout << theMap.description << std::endl << theMap.creature << std::endl;

return true;
}

int main()
{
std::cout << "map_render" << std::endl;
map_render();

std::cout << "\nmap_render2" << std::endl;
map_render2();

system("pause");
}



The map.txt file I'm using looks like this:
This is the description:This is the creature

Share this post


Link to post
Share on other sites
what pulpfist suggests will work but you should use getline(b_file,string) (where b_file is the ifstream you opened and string is a std::string found in the header string)for input as it avoids having a buffer over flow in your code.

Share this post


Link to post
Share on other sites
Have you given any consideration to using XML (tinyXML) or possibly an embedded database engine (SQLite)?

I still work with some text based MUDs that use flat files for their data however I have made the move to using SQLite.

I chose SQLite over XML files because it made sense for me (and SQL triggers helped me a ton with data creation). Your needs may differ.

Share this post


Link to post
Share on other sites
Well, I guess xml or sql is an overkill for my little project.
About portability, even compiling in release mode wont help it running on another machine that doesnt have .net framework

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!