I have this program where I'm trying to get text from a file and use it. Which is all well and good, I've managed to get the specific text from the file that I want. My problem is that I have a really long line so I put some '\n' in it, but when I grab them from the text file and output the string it just shows the '\n' as part of the string.
I'm confused as to why this is happening instead of the program just outputting a new line, and if there's a way to fix it.
In case you are wondering I made a test program to get the same problem I had with my main program and here's the test program code
Putting my txt file like you've suggested won't work for my purposes.
I need to be able to output multiple lines with just one use of a string, instead of putting the Hello World! into the string, outputting that, then putting the And Hello Again! into the string (overwriting the what was there before), and then outputting that.
The reason this won't work is because I am sending the string, which contains the text I just got from txt file, into a function and then breaking the loop.
/*
* room.cpp
*
* Created on: Aug 16, 2011
* Author: james ctr grider
*/
#include <iostream>
usingnamespace std;
#include "room.h"
Room::Room()
{
description = "This is an empty room.\n";
}
void Room::setDescription(string a)
{
description = a;
}
void Room::enterRoom()
{
cout << description;
}
and the text in Room_Descriptions.txt
1 2 3 4 5 6
Room_Descriptions.txt
Created on: Aug 16, 2011
Author: james ctr grider
1. You awaken to find yourself in a small bedroom.\nYou are on a bed and you notice a wallet sitting on the side table next to you.\nOn the far side of the room is a door.\n
As you can see I'm making a very simple MUD and I want the line starting with 1. which will be put into my string variable b then the 1. will be taken out and b will be sent to room a as it's description. This will then be returned to location.
I'm going to use your method it keeps me from having multiple lines in my txt file with things like:
1. something
1. something else
1. more for the same room