![]() |
| ||
| Phonebook program! I have a problem with search function by name ,could anyone help me? This my code so far!! Thanks in advance.
|
| ||
| Re: Phonebook program! >> search_nameFile.seekg( ( name - 1 ) * sizeof( phonebook) ); variable name is a std::string -- why are you attempting to treat it as an integer? I would think that function searchbyname() should seek to the beginning of the file then enter a loop to sequentially read each record until eof or the desired name is found. Your version of that function does not do that at all. |
| ||
| Re: Phonebook program! Quote:
This is it #include <iostream> |
| ||
| Re: Phonebook program! To answer your specific question, as a start, it would be helpful to indicate what the warnings are and what code you think the warning refers to. In a more general sense, I think you need to think about the relationship between what you refer to as phonebook, record, and person within your code. Using comments can help you dramatically in this regard. |
| ||
| Re: Phonebook program! Quote:
Deleting intermediate files and output files for project 'phonebook - Win32 Debug'. --------------------Configuration: phonebook - Win32 Debug-------------------- Compiling... phonebook.cpp e:\school\c++\c++\phonebook.cpp(305) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std ::char_traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255' characters in the debug information e:\school\c++\c++\phonebook.cpp(305) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char _traits<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug information e:\program files\microsoft visual studio\vc98\include\vector(39) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information e:\program files\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::~vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information Linking... phonebook.exe - 0 error(s), 4 warning(s) |
| ||
| Re: Phonebook program! There are few warnings that you should feel comfortable about ignoring, but warning C4786: is the exception to the rule. This particular warning is very common when I use VC6++ and STL containers like vectors. You can use a pragma statement to prevent them from showing up, use a different compiler, or ignore them. Since I forget the pragma statement syntax and don't want to get another compiler yet, I usually just ignore them. The bad news is that these warnings aren't the source of your problems. I think working on the other suggestion in my previous post will go a long way to fixing what ails your program. |
| ||
| Re: Phonebook program! put this as the very first line in stadafx.h but after include safeguards #pragma warning(disable: 4786) Note: NO semicolon! That warning only occurs when your program is compiled in debug mode and can safely be ignored. If you don't disable it, it will muddy up compiler complaints quite badly. |
| ||
| Re: Phonebook program! Quote:
Thnx ppl but still this program doesnt do eactly what i want to.. Have u ever!! i think i did all could but now i've got no clue how to approach this or what change it to make it work.... |
| ||
| Re: Phonebook program! To me at least, the member variables of the phonebook class represent the attributes of a person/customer or phonebook record, but they don't represent a phonebook. A phone book to me is a collection of phonebook records or people/customers. This means I think your C++ syntax is (mostly) correct (you mentioned two remaining warnings after adding the pragma statement, so there may still be some concerns with the syntax, too), but you have an underlying logic problem. I would redesign the program by renaming your phonebook class customer or person or record, and then determine which container class---array, list, map, set, vector, (?file?)---would be the most appropriate for a collection of customers/people/records. Then you could either keep the independent functions as listed and pass them the appropriate parameters or roll them into another class called phonebook that has a container of the customers/people/records as a member variable and the current independent functions as member variables. |
| All times are GMT -4. The time now is 11:42 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC