![]() |
|
#1
|
|||
|
|||
Including Maps and strings??Hi,
Can someone explain to me what I'm doing wrong in my C++ program(c attachement). I'm using maps and strings, so I've included the header files <map> and <string> and stil I get errors. Can someone please help me out, cause I don't see what I'm doing wrong. Thanks in advance, Maddie |
|
#2
|
||||
|
||||
|
Just so everyone can see it in the new and snazzy highlighting: See sticky thread above this for help in doing it:
CPP / C++ / C Code:
|
|
#3
|
|||
|
|||
|
Oh thanks... Now it looks much better...
But ehh... can you tell me if there's something wrong with my C++ program?? Cause everytime I compile this program I get the next error's: --------------------Configuration: result3 - Win32 Debug-------------------- Compiling... result3.cpp D:\result3.cpp(18 ) : error C2143: syntax error : missing ';' before '<' D:\result3.cpp(18 ) : error C2501: 'map' : missing storage-class or type specifiers D:\result3.cpp(18 ) : error C2059: syntax error : '<' D:\result3.cpp(18 ) : error C2238: unexpected token(s) preceding ';' D:\result3.cpp(20 ) : error C2065: 'map' : undeclared identifier D:\result3.cpp(20 ) : error C2065: 'string' : undeclared identifier D:\result3.cpp(20 ) : error C2065: 'global' : undeclared identifier D:\result3.cpp(21 ) : error C2065: 'countries' : undeclared identifier D:\result3.cpp(21 ) : error C2275: 'country' : illegal use of this type as an expression D:\result3.cpp(16 ) : see declaration of 'country' D:\result3.cpp(23 ) : error C2061: syntax error : identifier 'basic_string' D:\result3.cpp(24 ) : error C2601: 'read_country' : local function definitions are illegal Error executing cl.exe. result3.obj - 11 error(s), 0 warning(s) -------------------------------------------------- So is it possible to explain me what I'm doing wrong. I use map and string in my program and I've included the header files <map> and <string> and still I get these error's.... I thaught it would work after having included the header files.... Can someone explain please?? ![]() All help is appreciated...thanks... |
|
#4
|
|||
|
|||
|
Sorry for the lateness of this reply.
I don't like the way you've put the struct there, try placing it outside the main(). Also I don't like structs at all, it would work better if you made the country into an object, like so: CPP / C++ / C Code:
and use it pretty much in the same way (note capitalisation - handy for objects). But place it outside any function. Also, after you declare the templated object, say map<string,string> have a space before the name of it. Try those, and get back to me. GF |
|
#5
|
|||
|
|||
I want to use key's instead of map'sThanks for your help,
I've tried what you have adviced me to. But I get this error that map and string are undeclared identifiers. I've included the headerfiles map and string, but still get the error that map and string are undeclared identifiers. So yet I don't know if I'm still doing something wrong or that this error is caused by something else which I still have to discover. Anyway I think I'll try a different way instead of using maps I'll use key's, cause this is much easier. Cause what I'm trying to do with this program is to read specific values from a textfile. So I thought that if I define the name's of the objects I need and run a sort of scan through the textfile by reading it line by line, I'd be able to get the values I need. Afterwards I could assign these values to the variabels used in my C++ program. To use these values to create a sinus and write the results to another file depending on the name, country and tonename. That's why I wanted to use maps, but I think I've complicated it a bit. I think it's easier to use key's and run a scan through the textfile to detect the values. This is the textfile I want to read from: name = test duration = 4/6 amplitude = 100 #Amplitude in percents country = albania tone = dial, 425, cont #continuous tone tone = ringing, 425, 1.0-s4.0 #s stands for 'silence' tone = busy, 425, 0.3-s0.3, 4, 90 #Overruled duration & amplitude tone = congestion, 425, 0.15-s0.15, 4/6 #Overruled duration ------------------------------------------------------------------------ So that what is bold have to be the key's and that what is italic is the value I need to select and assign to variabels in my C++ program. The results will than eventually be written to a file named <name_country_tonename.inp> example: test_albania_dial.inp The prupose of my program is: - Reading values from a textfile - Assign the values to variabels in my c++ program - Using the values to calculate the sinus - Write the results to an inputfile (.inp). This is how I want to calculate the sinus and write it to another file, but this file has to be able to get different names instead of only result. Cause everytime I get other values the results will be written to the same file and thus the file will be overwritten. PHP Code:
|
|
#6
|
|||
|
|||
|
Lemme see if I've got you right.
You want to parse a text file, with key=value, and insert the key/value pair into a key/map/linked-list so you can use the stuff like variables? If I'm roughly there, give me a day to ponder over you're code. I've got my way of doing this, but it's very different to yours I'll post up some code of mine once I've it written, K? But what's worrying me the most is how some string & map are being called undeclared identifiers? Have you tested either of these, in a simple program? GF |
|
#7
|
|||
|
|||
|
Yes indeed I've to parse the textfile. The key/ value have to be inserted into the key/ map/ linked-lists to use as variables.
Afterwards these variables will be used to calculate the sinus. The resultst of these calculations will be written to a different file. Is it possible to complete this wthout using maps?? By the way I already have tested the header files string and map, string doesn't give any errors anymore but map still is. So what to do. Thank you very much for your help. |
|
#8
|
|||
|
|||
|
Hi ,
Is it possible to define a few strings and than run a scan through the textfile, detecting the predefined strings? Maddie |
|
#9
|
|||
|
|||
|
I'm really REALLY sorry for taking this long. I've the code written up at home, I'll post it ASAP (once I get my laptop working, it's in 50 pieces)
I've a seriously hectic new job, around 12 hours a day for the last 2 weeks, weekends inclusive! It's crazy, a company miles behind their deadline, and paying through the nose I'll have the code up in a few hours. GF |
|
#10
|
|||
|
|||
|
Just an FYI while you're waiting:
I've created 2 classes, one called a Tokeniser, which reads input and splits it up into chunks. So reading: name = Bert will have "name", "=", and "Bert". Then using this, the second class (a templated class) is a special linked list class, which stores each key/value pair. So the tokeniser reads a key, then an "=", then a value" it passes the key & value pair to the linked list. Then you can access the values of the keys by scanning through the list. GF |
Recent GIDBlog
Toyota - 2008 September Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The