|
Hello. I am having problems trying to print my vector. When it goes through the add it works, but when i want to use my printfunction it doesnt work. I have created a person struct and when the prompt comes around it is to be entered such as
>"add name @address #number
>"add name @address
>"add name #number
and then it is to print out the vectors at
>print
and it doesnt work for some reason
I have attached my code.
Thanks
karen
kginsberg@hotmail.com
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct person
{
string name;
string address;
string number;
};
void addfunc(string s, vector<person>& address1, int add)
{
person temp;
int addrindex, phoneindex;
addrindex = s.find('@');
phoneindex = s.find('#');
if(addrindex!=-1 || phoneindex!=-1)
{
if(addrindex<phoneindex)
{
="" temp.name="s.substr(add+3," addrindex-(add+3));
="" temp.address="s.substr(addrindex+1," phoneindex-(addrindex+1));
="" temp.number="s.substr(phoneindex+1," s.length()-(phoneindex+1));
=""
="" }
="" if="" (addrindex="">phoneindex)
{
temp.name=s.substr(add+3, phoneindex-(add+3));
temp.address=s.substr(addrindex+1, s.length()-(addrindex+1));
temp.number=s.substr(phoneindex+1, addrindex-(phoneindex+1));
}
}
if(addrindex==-1)
{
temp.name=s.substr(add+3, phoneindex-(add+3));
temp.address=" ";
temp.number=s.substr(phoneindex+1, s.length()-(phoneindex+1)); //phone index is the pound sign
}
if(phoneindex==-1)
{
temp.name=s.substr(add+3,addrindex-(add+3));
temp.number=" ";
temp.address=s.substr(addrindex+1, s.length()-(addrindex+1));
}
address1.push_back(temp);
//&address1.push_back(temp);
cout<<address1.size();
}
void print1(const="" vector<person="">& address1)
{
for (int i = 0; i < address1.size(); i++)
{
cout << address1[i].name <<address1[i].address<<address1[i].number<<endl;
}
}
="" *
void="" delfunc(int="" input,="" vector<person=""> &addressbook)
{
for (int i = input; i < addressbook.size() - 1; i++)
{
addressbook[i].name = addressbook[i+1].name;
addressbook[i].address = addressbook[i+1].address;
addressbook[i].number = addressbook[i+1].number;
}
addressbook.pop_back();
}
void findf(string input, vector<person> book)
{
int check;
for (int i = 0; i < book.size(); i++)
{
check = book[i].name.find(input);
if (check != string::npos)
//print current person
check = book[i].address.find(input);
if (check != string::npos)
//print current person
check = book[i].number.find(input);
if (check != string::npos)
//print current person
}
}
*/
void main()
{
char a[80];
vector<person> addressbook;
int add=0, print=0;
while (add!=-1)
{
cout<<" >";
cin.getline(a,80);
string s=a;
add=s.find("add");
addfunc(s, addressbook, add);
}
while (print!=-1)
{
cout<<" >";
cin.getline(a,80);
string s=a;
print=s.find("print");
print1(addressbook);
}
/* switch (action)
{
case "add":
addfunc();
break;
case "find":
findf(input, addressbook);
break;
case "del":
del();
break;
case "print":
print();
break;
case "exit":
cout <<"you are now exiting the program\n";
break;
default: cout << "\n> ";
}
*/
}
|
|
|
|
|
Hi
Does anyone know where I can find a nice tutorial about writing a DLL under VC++
Thanks
|
|
|
|
|
www.mindcracker.com
|
|
|
|
|
Thanks
|
|
|
|
|
Can any one tell me how can i create a toolbear with circular buttions?
Br
/
|
|
|
|
|
Your best bet is to check out a library such as BCG (http://www.bcgsoft.com) - it isn't free, but it allows you to create toolbar "skins" and includes an example of a toolbar with round buttons.
Regards.
|
|
|
|
|
I'm wondering if anyone has been successful in getting visual styles to work with a MDI application.
The problem is that toolbars are opaque and not permitting the gradient background to show through. If i set a dialogbar's background to transparent, it will flicker when resizing, and sometimes look like its supposed to. but otherwise, it will also disapear and other bad things.
the normal toolbars likewise do not work at all because of the same problem.
it seems the toolbars have a set background that is being used on the background when WM_PAINT comes down.
\\ Rock
|
|
|
|
|
Hello!
Why doesn't this work? First time it works, second time it returns blanks.
std::stringstream s1(std::stringstream::in | std::stringstream::out);
s1<<"hello";
string x1;
s1>>x1; //x1 contains hello. good
s1<<"more";
string x2;
s1>>x2; //nope. x2 contains blank
Thanks
-Rob
|
|
|
|
|
The code fails because the first 'read' operation on the stringstream results in 'eof'. The following line :
string x1;
s1>>x1;
causes the stream to the 'drained', so 'eof' is set. The next 'write' to the stream does not reset the 'eof' bit, so when you try the next 'read' :
string x2;
s1>>x2;
It fails because the inputbuffer of the stream has it's 'eof' bit set. I am not sure it is possible to work around this - as far as I know, it is not the intention of 'stringstream' to allow constant intermingling of 'reads' and 'writes' to the underlying string. I would think that once the stream has been 'drained', you need to either recreate or reinitialise the stream.
-----------------------
The sermon on the mount...
Man 1 : Hear that? Blessed are the greek.
Man 2 : The greek?
Man 1 : Well apparently, he's going to inherit the earth.
Man 2 : Did anyone catch his name?
|
|
|
|
|
Ah yes, thanks Mike , I added an s1.clear() and it works.
|
|
|
|
|
Must be getting sleepy - should have thought of 'clear()'!!!
-----------------------
The sermon on the mount...
Man 1 : Hear that? Blessed are the greek.
Man 2 : The greek?
Man 1 : Well apparently, he's going to inherit the earth.
Man 2 : Did anyone catch his name?
|
|
|
|
|
I want to create a program without any windows... Just an icon in the systemtray with a menu (when someone rightclicks the icon). Just like the well-known (I think) nail.exe. I can't find any help in MSDN. Can anyone help me?
Sprudling
|
|
|
|
|
You need to look at the following articles (from MSDN)
Jeff Richter - November 97 Q&A Win32 - explains how to control the visibility of an application's main window;
Paul DiLascia - March 1996 Q&A C++ - explains the basics of tray icons
-----------------------
Reg : "Well, what Jesus blatantly fails to appreciate is that it's the meek who are the problem."
|
|
|
|
|
http://www.codeproject.com/useritems/trayicons.asp
Is a pretty straight forward use putting an app in the system tray.
ModifyStyleEx(WS_EX_APPWINDOW, WS_EX_TOOLWINDOW);
Will make your window not appear on the taskbar or in the Alt tab menu choices.
make it reappear ModifyStyleEx(WS_EX_TOOLWINDOW, WS_EX_APPWINDOW);
should get you started, or get you finished.
Ryan
|
|
|
|
|
u can get help in MSDN pls search for Shell_NotifyIcon.Lot of info .
|
|
|
|
|
I get a lot of these warning messages, when I compile a program that uses STL maps.
identifier was truncated to '255' characters in the debug information
I do not think that it is a problem. But thought would take second opinion. If it is not an issue, how can I make it go away, ie, the message not to appear so that I can see the *real* errors in the *Build* window.
Thanks in advance for any help on this.
-Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
#pragma warning(disable:4786)
put this before (and sometimes after) any STL includes.
it's a harmless warning.
-c
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
Thank you very much.
I also had another question. Do you have any idea of the performance benefit or degradation when using STL containers instead of MFC containers? I have a set of programs that makes extensive use of MFC containers. But, for a new version of the program, I wanted to use SMART pointers and found that MFC containers are not typesafe. Hence the reason to move to STL. But, I also do not want to find out later that there is a performance degradation.
How would you rate MFC vs STL container (specifically maps) performance? Would using a library from stlport.org help?
Thanks again
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
i've heard VC's STL maps can be slower than MFC's CMap. but, i've also heard that other STL implementations can be faster.
try www.deja.com
-c
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
MFC containers are not typesafe??? What do you mean, which ones are you using?
Regards,
Alvaro
|
|
|
|
|
CPtrList, CTypedPtrList, CMapStringToPtr etc...
None of them are typesafe.
-Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Woah!
CPtrList is not type safe since it holds a list of void pointers. But CTypedPtrList is a type-safe “wrapper” for objects of class CPtrList (according to MSDN).
The CTypedWhatever classes are type-safe. The only ones that aren't are the CPtrWhatever and the CObWhatever classes. Also, CArray, CMap, and CList are type-safe.
Regards,
Alvaro
|
|
|
|
|
In general, you can suppress this warning using the pragma directive
#pragma warning(disable:4786)
However, this does not always work - in particular, I have noticed problems when mixing STL and MFC with the DEBUG macro (and adding in DLLs just for good measure). Microsoft has acknowledged that this pragma does not always work :
http://support.microsoft.com/support/kb/articles/Q167/3/55.ASP - "BUG: C4786 Warning Is Not Disabled with #pragma Warning"
You should also look at installing and using the "STL Error Message Filter" from BDSoft (http://www.bdsoft.com/tools/stlfilt.html) - it's free, and very, very good at turning STL errors into english!
-----------------------
Reg : "Well, what Jesus blatantly fails to appreciate is that it's the meek who are the problem."
|
|
|
|
|
In my case the pragma directive works. Maybe because I am not using MFC in this application at all.
Also, I asked earlier also, do you have any experience using STL containers and their relative performance compared to MFC containers, especially maps?
Thanks a lot.
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
No, I have no idea of the relative efficiencies of MFC versus STL containers - I have been using STL heavily for the past 3 years, and prior to that I used a library of custom built containers. I have never used MFC containers. I would expect STL to be similar to MFC in performance, but I do know that there have been examples of STL running much slower than MFC in specific instances. I believe this is due mainly to the fact tht MFC was designed in the early ninties, when PCs were NOT equiped 1gig CPUs, and therefore a fair amount of effort went into building a libraray that had reasonable performance. STL, on the other hand, is designed for portability and flexibility (via extension), and the entire container/iterator/algorithm framework has at least some inherent overhead. I have never found STL to be a 'choke-point' in my code, however.
Your quickest answer is probably to code up a simple test - build a small MFC exe that has a std::map and a CMap, then try filling, sorting, searching, removing. put it all into a loop, run it 10000 times, see how long it takes.
-----------------------
Reg : "Well, what Jesus blatantly fails to appreciate is that it's the meek who are the problem."
|
|
|
|