i read a file, and the file contains this: -
+-------------------+
-
| |
-
+-------------------+
-
when i read it into array, and then display it out to cout exactly the same as display in text file, but i failed to do so. it give me this : -
+++++++++++++++++++++++
-
+++++++++++++++++++++++
-
+++++++++++++++++++++++
-
here is my code(it is the constructor ): -
Terrain(char* filename =" " ): width(25) , height(11), ter_array(width, height){
-
-
ifstream in(filename);
-
if(!in){
-
cout << "Cannot open terrain file." << endl;
-
}
-
-
while(in >> piece){
-
for(unsigned y = 0; y < height; y++){
-
for(unsigned x = 0; x < width; x++){
-
ter_array.Put(x,y,piece);
-
}
-
}
-
}
-
in.close();
-
}; // should i put ; in the end of this constructor?
-
note the comment line.
any one help...pls
I want the space inside the text file, store in array, so that it display the exactly the same to cout as in text file.
thanks in advance.
Nick
4 2055
The nested loops concern me, especially the while....
The exact logic I'm not sure of, but I think basically, you always populate your array with all of 1 character...This means the array is full of (copies) of the current character at any time. because + is your last character, thi is what fills the array after you have read from the file.
Since you know the height & width, you could instead do something like: -
Terrain(char* filename =" " ): width(25) , height(11), ter_array(width, height){
-
-
ifstream in(filename);
-
if(!in){
-
cout << "Cannot open terrain file." << endl;
-
}
-
-
-
for(unsigned y = 0; y < height; y++){
-
for(unsigned x = 0; x < width; x++){
-
in>>piece;
-
ter_array.Put(x,y,piece);
-
}
-
}
-
-
in.close();
-
}; // should i put ; in the end of this constructor?
-
As far as I know too many semi-colons are never a problem, so even if you don't need the last one, there is little harm in including it
thanks but still, it cannot "get" whitespace between the characters.
the original text file: -
+-----------------------+
-
| |
-
| +-+--+ +-+
-
| | |
-
| +----+ +-------+ |
-
| | | |
-
| | +---+ + |
-
| | | |
-
| +-----+ +--+ + |
-
| | |
-
+------------------+----+
-
the whitespace inside the terrain, i want to saved them as one character with ' '.
Any method to get all the whitespace?
you could try using getchar() et al to get input....
getchar() fails.
but get() works.
thanks for the tip.
:)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Xah Lee |
last post by:
how to represent the unicode "em space" in regex?
e.g. i want do something like this:
fracture=re.split(r'\342371*\|\342371*',myline,re.U)
Xah
xah@xahlee.org
∑ http://xahlee.org/
|
by: Petr Jakes |
last post by:
Hi,
I am trying to set-up communication to the coin change-giver from my
Linux box using the Python code. The change giver uses MDB (Multi Drop
Bus) serial protocol to communicate with the...
|
by: serge |
last post by:
I have an XML file with an XSD file. When i am reading the XML
file and putting its content into a DataSet I notice that the field that
has a single space character is being converted to a field...
|
by: Steve |
last post by:
I am suddenly getting the obnoxious error C1060 when I try to compile
my project. I have tried adjusting the /Zm switch as suggested by the
help documents, but this is a project setting and not a...
|
by: Kannan |
last post by:
In section 7.19.6.1 on ISO C specification, it says about a format
character "space". When and how we will use this "space" format? I mean
is there a usage, for e.g. like printf("%space",...); ?
...
|
by: Lloyd Dupont |
last post by:
I am "defining" an XML schema.
In fact I'm not really writing any schema but I am writing an XML writer and
reader for my data.
It's all custom XML and I would like it to be XML tool friendly.
...
|
by: Sound |
last post by:
Enter space bar for field names and save the field.The field shoud not
get saved and an alert should be there as"Space bars are not allowed"
Add a field without giving any name and save the...
|
by: pippyn |
last post by:
I'm programming for a CE device with reduced key board, no mouse, and no touch screen. As such, I have to tab from button to button to get the focus on the button i want. Then to invoke the button...
|
by: blazedaces |
last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |