|
Easiest way is to read each line into a string first, then use an istringstream to get the second token in that string:
#include <iterator>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main()
{
ifstream ff( "test.txt", ios::in );
if ( !ff.is_open() )
return -1;
string name;
vector<string> names;
while( !ff.eof() )
{
std::string line;
std::getline(ff, line);
std::istringstream iss(line);
std::string first, second;
iss >> first >> second;
if (iss)
names.push_back(second);
}
copy (names.begin(), names.end(), ostream_iterator<string>(cout,"\n"));
return 0;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks stuart, it works nicely.
|
|
|
|
|
I've been working my way out of the console apps and I am now trying to learn how to use windows forms in visual studio 2008.
Anyway, onward to the question.
I am trying to display a numerical value as text in a label on a windows form. I looked around for an answer on the internet and I found some, but I couldn't get them to work for me. So I decided to start from scratch and just ask this forum for help.
Here's the section of code I'm dealing with, I bolded my problem areas.
Oh and to avoid confusion, click this: http://img100.imageshack.us/img100/4479/form1w.jpg[^]. Its a picture of my form with all of the variables and etc labeled.
private: System::Void numberDisp_Click(System::Object^ sender, System::EventArgs^ e)
{
numberDisp->Text = ticketNumber->Value
}
private: System::Void priceDisp_Click(System::Object^ sender, System::EventArgs^ e)
{
int tickNum = 0;
double price = 0;
tickNum = ticketNumber->Value;
if (locB->Checked == true)
{
price = tickNum * 75;
}
if (locP->Checked == true)
{
price = tickNum * 30;
}
if (locL->Checked == true)
{
price = tickNum * 21;
}
priceDisp->Text = price;
}
|
|
|
|
|
Try using the ToString method:
priceDisp->Text = price.ToString();
Also, maybe you could use the correct forum[^] - you're more likely to get the correct answer there.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Bah, sorry about the forum
This is the second time I've done this (accident).
|
|
|
|
|
Hi All,
I've used the example from the below link to build a small application.
http://www.codeproject.com/KB/cpp/Simple_Tab_Control.aspx
One thing I've tried to add to it, but cannot figure out how is....
When I Click on a particular Tab, I want to jump into a function in that PP's class.
For Example, if I have a btn on tab 2 called "GetData" then I want to run the function CPPTwo::OnBnClickedGetData as soon as I click on the Tab.
I cannot get a pointer to the class from the OnTcnSelchange function, not sure how to get it either.
Any suggestion will be much appreciated.
Cheers
R
|
|
|
|
|
When a property page is activated, it will be shown - I think it'll be sent the WM_SHOWWINDOW [^] message? Add a handler for that to each of your property page classes and you can call whatever methods you want.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: When a property page is activated, it will be shown - I think it'll be sent the WM_SHOWWINDOW[^] message?
Or the PSN_SETACTIVE notification.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Thanks for the suggestions...they got me going in the right track....
Here is the resolution/what I ahve done now to implement what I set out to do....
Scenario is I have a Tabbed application, where each of the tabs are a CPropertyPage (reference: see Venura's Simple Tab Control)
and my objective was to run a member function of a Tab when a user clicks into the Tab
In the Tab's/PP's class add the handler
CPPTwo.h
afx_msg void OnWindowPosChanged(WINDOWPOS *pwp);
CPPTwo.cpp
BEGIN_MESSAGE_MAP(CPPTwo, CPropertyPage)
.
.
ON_WM_WINDOWPOSCHANGED()
.
.
END_MESSAGE_MAP()
Then add the member function
void CPPTwo::OnWindowPosChanged(WINDOWPOS *pwp)
{
if ((pwp->flags & SWP_SHOWWINDOW))
{
}
}
msdn reference: WM_SHOWWINDOW Notification,
http://msdn.microsoft.com/en-us/library/ms632645.aspx
In this if you look under Community Content section you'll see Use WM_WINDOWPOSCHANGED to react to window state changes
This is Raymond Chen's blog.. which is what I followed to acheive what I wanted.
here the link to the blog:
http://blogs.msdn.com/oldnewthing/archive/2008/01/15/7113860.aspx
Cheers
Ranga
-Remember Coding is fun.... coding with bugs makes it even more fun....
|
|
|
|
|
Hi
I would like to read each number (integer and float) and a word (e.g. E1) in between these numbers:
1,1,1,E1,0.13060,-0.40193,-0.90631
7,1,1,A25,0.13060,-0.40193,-0.90631
Using the statement:
char buffer[15];
for (i=0;i<2;i++)
{
fscanf(f_ptr1,"%i,%i,%i,%s,%f,%f,%f\n",&kdum[i],&nlinks[i],&ndih[i],buffer,&cos_xx[i],&cos_yy[i],&cos_zz[i]);
...
}
"buffer" should read only "E1", but it reads: "E1,0.13060,-0.40193,-0.90631"
I need:
kdum[0]= "1"
nlinks[0]="1"
ndih[0]="1"
buffer="E1"
cos_xx[0]="0.13060"
cos_yy[0]="-0.40193"
cos_zz[0]="-0.90631"
kdum[1]= "7"
nlinks[1]="1"
ndih[1]="1"
buffer="A25"
cos_xx[1]="0.13060"
cos_yy[1]="-0.40193"
cos_zz[1]="-0.90631"
Thanks for help
modified on Monday, February 23, 2009 6:33 PM
|
|
|
|
|
By default, reading a string using fscanf reads until the next whitespace (that'll be the EOL).
Either change the number of characters read for the string or change the string delimiter. This page of the documentation[^] gives the necessary details.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I can not change the delimiter. I have to read as they are.
|
|
|
|
|
No - change the delimiter that fscanf uses as denoting the end of the string. Did you read the documentation I pointed you at?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
You'd be better off reading the whole line into a string buffer and then tokenizing it. If you can't go that route, then fscanf() 's format argument will need to change. It's easy to do, but very ugly and prone to error.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi David,
If you can give me some key code fragments for the tokenize, that would be a great help.
Thanks
|
|
|
|
|
strtok() (C)
AfxExtractSubString() (MFC)
CStringT::Tokenize() (MFC)
C++ does not have a formal string tokenizer, but it's very easy to create one using a vector to hold the tokens. You may also be able to do it via istringstream .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
after tokenizing, how to convert char to float ?
float ff;
ff = float(strtok(string, seps));
not working
|
|
|
|
|
mrby123 wrote: after tokenizing, how to convert char to float ?
Use atof() .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi,
I have tried to build a project which has written in vc++/MFC. The project last build with 7.10 version and I am trying to build it using VS.Net 2003 and VC++ compiler version 7.1.3088. When it reaches to the part "Linking" start throwing the following type of link errors,
error LNK2005: "private:_thiscall type_info::(classs type...
error LNK2005 _abort already defined in libcmtd.lib(dbgheap.obj)
etc
I am sure , no error is there with the program and it is compiling fine..I would really appreciate if anybody can show me the right way to resolve these type of errors.
Note: I have seen the existing project contains a file with ".odl" extension and I changed to ".idl" because I found while creating a new project it is creating ".idl".
Thanks In Advance.
Rahul
SoftwareDeveloper(.NET)
|
|
|
|
|
That looks very much like you're linking your program against two versions of the C runtime library somewhere. The 'already defined in libcmtd.lib' bit gives it away.
Can you check that all projects in the solution have the same runtime library selected in the C/C++->'Code Generation' property page?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi Stuart Dootson,
Thanks much for your response. I have checked the runtime library and its same for all the projects. ("multi-threaded debug"(/Mtd)). One difference I found is that, some projects having Basic runtime checks as default and some having "both".
When I tried to rebuild each project separately, only one project was showing link error ...All other projects got rebuilded file.
Please let me know if you have any other suggestion.
Thanks,
Siju Thomas.
SoftwareDeveloper(.NET)
|
|
|
|
|
Since I couldn't find a way to solve the linking error, I have tried to create a new project and replaced the automatically created files and added the files from the existing project..when I build that it was able to link with out any Issues..It didn't throw any linking error.
But, I have got another error which is given below.
while debugging
"error PROJ0019: A tool returned an error code from "Performing Registration"
While manually resistering the ocx
" DLLRegister failed, Return code was: 0*80040200"
Any idea to resolve this?
Thanks,
Rahul.
SoftwareDeveloper(.NET)
|
|
|
|
|
hi all!
Can any one tell me how can we create a satellite DLL to support german languagae....for an MFC aplication.
Reply ASAP....
Regardx!
|
|
|
|
|
Well, creating a DLL is quite simple, on the other hand, putting it into orbit is a rather complex task.
BTW: Do you know the powerful CodeProject's article search engine? [^]
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
In the properties of the DLL project, set the "No Entry Point" property in the advanced linker options to true.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|