![]() |
|
#11
|
||||
|
||||
|
Sorry 'bout that marita. I don't have problems using getline() that way. Does using the std:: in either way suggested solve the problem?
I compile with GNU gcc for cygwin and differences are very possible. Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
||||
|
#12
|
|||
|
|||
|
Its okay.
yeah, the std::getline fixed the problem, but still i cant get the code to work. Here's the output: PhoneBook Last First Phone number Juanita RivePepiPanchita Marie NievesJuanita RivePepiPanchita PepiPanc hita-Panchita PhoneBook Last First Phone number - PhoneBook Last First Phone number - PhoneBook Last First Phone number - PhoneBook Last First Phone number - Press any key to continue IS there way that i can get the file to output correctly and make corrections to it as suggested. I explain my self. That if the user wants to edit the area code he can. That if the user wants to edit the phone number he can. That if the user wants to edit the entire thing (phonenumber, area code and name) he can? |
|
#13
|
||||
|
||||
|
I would be willing to be your .txt file looks a lot different than mine. By using getline you are reading in the entire line in the file, and putting it in each variable in turn. Perhaps yours needs to look for spaces or something else. Could you post the phonebook.txt.
Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#14
|
|||
|
|||
|
Here's the .txt:
code]Marie Nieves (555) 555-5555 Juanita Rivera (777) 777-7777 Pepito Conde (888) 888-8888 Panchita Cruz (999) 999-9999[/code] |
|
#15
|
|||
|
|||
|
do you need anything else?
|
|
#16
|
||||
|
||||
|
Quote:
Actually yes. I introduced using a string and getline without knowing if you can even use these for your project. Can you and are you familiar with using them? Also, do you have any suggestions on how to do this? I am reading in a complete line from your file and it will now have to be parsed for spaces and put the proper values in the proper place. Anything else of value you may want to add will be helpful. You could also take a look at how I declare the PhoneNumber objects. It is not dynamic. Make some suggestions there. Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#17
|
||||
|
||||
|
Ok, this is a really straight forward way to load your variables. I am assuming you can use getline and strings for this. Not fancy, the code could be reduced by about two thirds but since I don't know if you have a plan of attack this will have to serve for now.
The .txt file you had has 4 items per line, each ending in a space. That is a tip off right there. There is a function isspace(string) that can be called to check when you find it. Here is the general concept. You get your line from the file using getline. input = "Marie Nieves (555) 555-5555 " So now you want everything up to the first space (but not the space) to be placed in FirstName which is a character array. I increased the sizes of your arrays as some were too small and were being overrun. Always remember your total number of chars plus your termination make up the char string. Here is the beginning of the new member function. CPP / C++ / C Code:
First I set all the char arrays to be empty by placing a '\0' in the first position. Then the while loop copies the string passed (adding the terminator) until it finds a space. Then the passed string is cut, the index is reset and off to the races again and again and finally for the PhoneNumber. It is linear and boring but it works well. Since this code is repeated with the different variable names you may be better served by reducing the fuction to this and passing a cut version of the input string. Here is how I called it from main. CPP / C++ / C Code:
Well, digest that and come up with a plan for the rest. Hope this gets you on your way. If you have any question ask. Someone here will most likely be able to answer them. Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#18
|
|||
|
|||
|
CPP / C++ / C Code:
the errors are: c:\documents and settings\ee181\desktop\cpp1.cpp(26) : error C2143: syntax error : missing ';' before '.' c:\documents and settings\ee181\desktop\cpp1.cpp(26) : error C2501: 'fp' : missing storage-class or type specifiers c:\documents and settings\ee181\desktop\cpp1.cpp(26) : error C2143: syntax error : missing ';' before '.' c:\documents and settings\ee181\desktop\cpp1.cpp(2 c:\documents and settings\ee181\desktop\cpp1.cpp(2 c:\documents and settings\ee181\desktop\cpp1.cpp(2 c:\documents and settings\ee181\desktop\cpp1.cpp(2 c:\documents and settings\ee181\desktop\cpp1.cpp(2 c:\documents and settings\ee181\desktop\cpp1.cpp(2 c:\documents and settings\ee181\desktop\cpp1.cpp(2 c:\documents and settings\ee181\desktop\cpp1.cpp(2 c:\documents and settings\ee181\desktop\cpp1.cpp(2 c:\documents and settings\ee181\desktop\cpp1.cpp(36) : error C2143: syntax error : missing ';' before '.' c:\documents and settings\ee181\desktop\cpp1.cpp(36) : error C2143: syntax error : missing ';' before '.' c:\documents and settings\ee181\desktop\cpp1.cpp(37) : error C2143: syntax error : missing ';' before '{' c:\documents and settings\ee181\desktop\cpp1.cpp(37) : error C2447: missing function header (old-style formal list?) c:\documents and settings\ee181\desktop\cpp1.cpp(54) : error C2065: 'cout' : undeclared identifier c:\documents and settings\ee181\desktop\cpp1.cpp(54) : error C2297: '<<' : illegal, right operand has type 'char [27]' c:\documents and settings\ee181\desktop\cpp1.cpp(54) : error C2065: 'endl' : undeclared identifier c:\documents and settings\ee181\desktop\cpp1.cpp(55) : error C2297: '<<' : illegal, right operand has type 'char [28]' c:\documents and settings\ee181\desktop\cpp1.cpp(56) : error C2297: '<<' : illegal, right operand has type 'char [21]' c:\documents and settings\ee181\desktop\cpp1.cpp(57) : error C2297: '<<' : illegal, right operand has type 'char [24]' c:\documents and settings\ee181\desktop\cpp1.cpp(5 c:\documents and settings\ee181\desktop\cpp1.cpp(59) : error C2297: '<<' : illegal, right operand has type 'char [10]' c:\documents and settings\ee181\desktop\cpp1.cpp(60) : error C2297: '<<' : illegal, right operand has type 'char [10]' c:\documents and settings\ee181\desktop\cpp1.cpp(62) : error C2065: 'cin' : undeclared identifier c:\documents and settings\ee181\desktop\cpp1.cpp(62) : warning C4552: '>>' : operator has no effect; expected operator with side-effect c:\documents and settings\ee181\desktop\cpp1.cpp(6 c:\documents and settings\ee181\desktop\cpp1.cpp(69) : error C2065: 'name' : undeclared identifier c:\documents and settings\ee181\desktop\cpp1.cpp(69) : error C2065: 'last' : undeclared identifier c:\documents and settings\ee181\desktop\cpp1.cpp(69) : error C2146: syntax error : missing ';' before identifier 'name' c:\documents and settings\ee181\desktop\cpp1.cpp(69) : warning C4552: '>>' : operator has no effect; expected operator with side-effect c:\documents and settings\ee181\desktop\cpp1.cpp(71) : error C2065: 'cant' : undeclared identifier c:\documents and settings\ee181\desktop\cpp1.cpp(74) : error C2065: 'data' : undeclared identifier c:\documents and settings\ee181\desktop\cpp1.cpp(74) : error C2109: subscript requires array or pointer type c:\documents and settings\ee181\desktop\cpp1.cpp(74) : error C2065: 'toupper' : undeclared identifier c:\documents and settings\ee181\desktop\cpp1.cpp(74) : error C2109: subscript requires array or pointer type c:\documents and settings\ee181\desktop\cpp1.cpp(74) : error C2106: '=' : left operand must be l-value c:\documents and settings\ee181\desktop\cpp1.cpp(76) : error C2065: 'strcmp' : undeclared identifier c:\documents and settings\ee181\desktop\cpp1.cpp(76) : error C2065: 'array' : undeclared identifier c:\documents and settings\ee181\desktop\cpp1.cpp(76) : error C2109: subscript requires array or pointer type c:\documents and settings\ee181\desktop\cpp1.cpp(76) : error C2228: left of '.name' must have class/struct/union type c:\documents and settings\ee181\desktop\cpp1.cpp(76) : error C2143: syntax error : missing ';' before '&&' c:\documents and settings\ee181\desktop\cpp1.cpp(77) : error C2143: syntax error : missing ';' before '{' c:\documents and settings\ee181\desktop\cpp1.cpp(7 c:\documents and settings\ee181\desktop\cpp1.cpp(7 c:\documents and settings\ee181\desktop\cpp1.cpp(85) : error C2228: left of '.cout' must have class/struct/union type c:\documents and settings\ee181\desktop\cpp1.cpp(85) : error C2297: '<<' : illegal, right operand has type 'char [68]' c:\documents and settings\ee181\desktop\cpp1.cpp(86) : error C2146: syntax error : missing ';' before identifier 'name' c:\documents and settings\ee181\desktop\cpp1.cpp(86) : warning C4552: '>>' : operator has no effect; expected operator with side-effect c:\documents and settings\ee181\desktop\cpp1.cpp(91) : error C2109: subscript requires array or pointer type c:\documents and settings\ee181\desktop\cpp1.cpp(91) : error C2109: subscript requires array or pointer type c:\documents and settings\ee181\desktop\cpp1.cpp(91) : error C2106: '=' : left operand must be l-value c:\documents and settings\ee181\desktop\cpp1.cpp(93) : error C2109: subscript requires array or pointer type c:\documents and settings\ee181\desktop\cpp1.cpp(93) : error C2228: left of '.name' must have class/struct/union type c:\documents and settings\ee181\desktop\cpp1.cpp(93) : error C2143: syntax error : missing ';' before '&&' c:\documents and settings\ee181\desktop\cpp1.cpp(94) : error C2143: syntax error : missing ';' before '{' c:\documents and settings\ee181\desktop\cpp1.cpp(95) : error C2109: subscript requires array or pointer type c:\documents and settings\ee181\desktop\cpp1.cpp(95) : error C2059: syntax error : '[' c:\documents and settings\ee181\desktop\cpp1.cpp(102) : error C2228: left of '.cout' must have class/struct/union type c:\documents and settings\ee181\desktop\cpp1.cpp(102) : error C2297: '<<' : illegal, right operand has type 'char [68]' c:\documents and settings\ee181\desktop\cpp1.cpp(103) : error C2146: syntax error : missing ';' before identifier 'name' c:\documents and settings\ee181\desktop\cpp1.cpp(103) : warning C4552: '>>' : operator has no effect; expected operator with side-effect c:\documents and settings\ee181\desktop\cpp1.cpp(10 c:\documents and settings\ee181\desktop\cpp1.cpp(10 c:\documents and settings\ee181\desktop\cpp1.cpp(10 c:\documents and settings\ee181\desktop\cpp1.cpp(110) : error C2109: subscript requires array or pointer type c:\documents and settings\ee181\desktop\cpp1.cpp(110) : error C2228: left of '.name' must have class/struct/union type c:\documents and settings\ee181\desktop\cpp1.cpp(110) : error C2143: syntax error : missing ';' before '&&' c:\documents and settings\ee181\desktop\cpp1.cpp(111) : error C2143: syntax error : missing ';' before '{' c:\documents and settings\ee181\desktop\cpp1.cpp(112) : error C2109: subscript requires array or pointer type c:\documents and settings\ee181\desktop\cpp1.cpp(112) : error C2059: syntax error : '=' c:\documents and settings\ee181\desktop\cpp1.cpp(125) : error C2228: left of '.cout' must have class/struct/union type c:\documents and settings\ee181\desktop\cpp1.cpp(125) : error C2297: '<<' : illegal, right operand has type 'char [12]' c:\documents and settings\ee181\desktop\cpp1.cpp(131) : error C2297: '<<' : illegal, right operand has type 'char [30]' Error executing cl.exe. Cpp1.obj - 71 error(s), 4 warning(s) |
|
#19
|
||||
|
||||
|
That's what I like to see, code to cut and paste and an errorlog.
To start with, you have a block of code that does not make any sense to the compiler. Quote:
One thing to keep in mind when you are posting code is to copy and paste your code EXACTLY as you are working on it. It seems there is some discrepency between your errors and posted code. Luckily, I like troubleshooting. Your first error and my first error (after copying your posted code) are as follows: Code:
The compiler is trying to make sense out of this and not having much luck. There are other related errors but let's just get rid of them by commenting out the offending block for the time being. You have a comment (c-style /**/) that I changed to '//' for now so I could comment out the entire block. Saving a compiling that should give you this as your first error and the rest should be the same as you posted. Code:
This is telling you that cout is currently nothing. It is not a way to output to the console, in fact, you could probably declare it as a variable or function at this point. Not that it would help anything, my point is, cout means nothing yet. So how do we fix that. First off, how do you add something that is not defined and/or implemented in your own code. Ah ha! CPP / C++ / C Code:
Anything starting with the pound sign is a compiler directive. That is to say, those lines are telling the compiler (or some sort of preprocessor) something about our code. In this case we want to include the file that lets us use cout. That would be <iostream>. So at the top of the file add the line: CPP / C++ / C Code:
The other is to use double quotes instead of less than greater than. This should look in the directory you are in for the file although it may then go looking in the magic places. As the same unnamed quoted member above might say, "Your milage may vary." So now the usefulness of iostream is now added to your program. But wait you say, no errors were removed when I tried to recompile. Oh, that is because we forgot to say what if anything we wanted to use from iostream. Now, I could wander off into an explanation of namespaces but if you are really interested in that rot use google or a text or something. I will just say that if you don't have a using somewhere, you aren't using anything. Add the following to the top of your file. CPP / C++ / C Code:
That reduces the number of errors quite considerably. But you really don't know why yet, do you? What we have done is allowed use by our program of anything (including the kitchen sink) that exists in the standard namespace. That is where c++ sticks pretty much everthing it might possibly need. Kind of like packing six suitcases when you are going to stay overnight at a friend's house. A little bit of overkill and you really don't learn anything by it. So, to get down to just a backpack of things we will only declare our intention to use the things we are using. To do this we will change the using a little. The standard namespace is referred to with the scope resolution of Code:
CPP / C++ / C Code:
That brings my next error to be this line: CPP / C++ / C Code:
Code:
Now we are in the meat of it. These variables you want to use need to be declared locally in main. Enough for now, fix the errors you can, post questions and get this thing working. Please, post your EXACT code you are using to compile with your next set of questions and your EXACT errors as you did above. My only suggestion is to enclose the error codes in the [code] with the appropriate [/ code] to keep the smilies out. That is how the generic code sections were created in my post. Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#20
|
||||
|
||||
|
Apparently I wasn't paying close enough attention in class yesterday. I didn't register that you had changed the names of the PhoneBook data members. So declaring them in main is not what you want to do.
Quote:
PhoneBook::name and PhoneBook::lastname need to have an object to work on. In the older version of your code they were char arrays. Now they are just a char. I think you must want an array so you can store the names not just the first character? In main, you need to create at least one variable of type PhoneBook to have access to the members. In the last code it was array[5]. That looked like the one that you wanted to declare dynamically using new once you get things under way. Look back at the old code and see how you were doing it. One thing to keep in mind as you learn is the thing I have been stressing, if you add a little bit at a time so you know the structure of your program is at least on the surface correct it is easier to find problems and implement new code without having to fight with 50 errors at a time. You seem to have the basis for your menu loop set up. It is not quite correct yet but the idea is sound. Once you enter the menu you loop until you get an option or quit. Once again though, you don't have a PhoneBook object, you haven't read in your file nor have you even declared an intention to use it. You should be able to get that code from the older version of your program and add it to the new one with the menu. Mark EDIT: One last thing. In order to get your code to compile (without correcting it myself anyhow) I commented out the body of your switch statements and replaced them with a single cout. CPP / C++ / C Code:
I also did this with case 2 and 3. After compiling and running I still can't choose any options. There is also an error in your while condition that is easy to catch. The problem is you are reading in a char but not testing for a char. To check against a char you need to do something like: CPP / C++ / C Code:
Simply put: CPP / C++ / C Code:
That essentially constitutes your do ... while loop in main. __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs Last edited by cable_guy_67 : 05-May-2005 at 06:42.
|
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The