|
What exactly is it that you are trying to do?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I'm tring to find any suggestion to correct my program code so that I can fix and use it.
If I cannot use thread to my limitation knowledge, can any one tell me what other method that I can use to recall void CConversion::OnAnyMove
If that bother you or others, I'm really sorry.
|
|
|
|
|
crieagu wrote: If I cannot use thread to my limitation knowledge, can any one tell me what other method that I can use to recall void CConversion::OnAnyMove
Using a secondary thread to call a function/method is obviously inefficient. Just call the said function/method and be done with it. If you are trying to do something else, please elaborate.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi all
The below code is reading string and then tokenizin it and reading all the info. But i want to call a csv file and it should then read a string from dt file. So what midification should i do in the below code. Its main code, all the functions are defined well. So just wanna know how to include some extra code to open the file and read each line.
Thanks a lot
typedef struct
{
string firstName;
string surname;
unsigned int HouseNumber;
string StreetName;
string Town;
unsigned int PostCode;
string email;
unsigned int Phone;
}Person;
int main(int argc, char* argv[])
{
string data = "James,Bond,33,AlberStreet,Manchester,HG231,abc@yahoo.com,2552423";
string delimiter = ",";
StringTokenizer strtok(data,delimiter);
StringTokenizer strtok(data,delimiter);
if(strtok.countTokens() != 8)
{
cout << "!-Error-! Not enough tokens!" << std::endl;
}
else
{
Person person;
person.firstName = strtok.nextToken();
person.surname = strtok.nextToken();
person.HouseNumber = strtok.nextIntToken();
person.StreetName = strtok.nextToken();
person.Town = strtok.nextToken();
person.PostCode = strtok.nextIntToken();
person.email = strtok.nextToken();
person.Phone = strtok.nextIntToken();
}
}
|
|
|
|
|
Any help would be greatly appreciated.
I am stucked cos of this and cant move on with the rest of the coding till i solve this....
Thanks
|
|
|
|
|
For a software specialist you sure have a lot to learn
There are many ways to read a line of text from a file. I find the easiest way is to use CStdioFile::ReadString . If you do not or can not use MFC then you could use ifstream::getline although the shortfall of getline is that it requires a preallocated buffer. ifstream::operator >>(std::string &) also can be used but it breaks at any and all whitespaces.
If I am stuck using STL streams I use my own overloaded operator >>() :
std::tifstream& operator >>(std::tifstream &stream, std::tstring &string)
{
string.clear();
TCHAR ch = 0;
while (!stream.eof() && !stream.fail() && ch != _T('\n'))
{
if (0 != ch) string += ch;
stream._Read_s(&ch, 1, 1);
}
return stream;
} It might not be the most efficient, but it works as a standard C++ stream extractor and it extracts the entire string, from the start right up to the newline character.
Example usage - dumps a text file to the console output:
int _tmain(int argc, _TCHAR* argv[])
{
std::tifstream f(argv[1]);
std::tstring s;
while (!f.fail() && !f.eof())
{
f >> s;
std::tcout << s << std::endl;
}
return 0;
}
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
PJ Arends wrote: you could use ifstream::getline although the shortfall of getline is that it requires a preallocated buffer.
This isn't the case as I underdstand it. For example, consider the following code:
#include "StdAfx.h"
#include <iostream>
#include <string>
int main()
{
using namespace std;
string line;
if (getline(cin, line))
{
cout << "Line read was \"" << line << "\"" << endl;
}
return 0;
}
This code works (even on MSVC6!) but there is no preallocated buffer. Granted I'm not calling ifstream::getline but that's not where the method we need lives!
Steve
|
|
|
|
|
Learn something new every day, thanks!
All that being said, I still prefer MFC over fstreams for file handling.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
#include "StdAfx.h"
#include <iostream>
#include <string>
int main()
{
using namespace std;
string line;
if (getline(cin, line))
{
cout << "Line read was \"" << line << "\"" << endl;
}
return 0;
}
Steve
|
|
|
|
|
Hi thanks for the reply
Well in the code you mentioned you never opened any file.So what line is it reading.
Or here you hv just nt included dt as you giving example .
Well actually problem is that i have tried so many programs by now...but none of them are opening the file. I dont know where am i going wrong....just now i tested 3-4 different programs but same it doesnt open the file...I am real stucked here..i ll try with your code by adding
std::ifstream InFile( "data.txt" );...dont knw if it gonna work or not...
Thanks
|
|
|
|
|
The sample I gave reads from the standard input stream; the file used is the console or a file if input redirection is used. To use a file specific file use code like this:
#include "StdAfx.h"
#include <iostream>
#include <fstream>
#include <string>
int main()
{
using namespace std;
ifstream file("C:\\File.txt");
if (!file)
{
cerr << "Failed to open input file!" << endl;
return 1;
}
unsigned int count = 0;
string line;
while (getline(file, line))
{
cout << "Line " << ++count << ": " << line << endl;
}
return 0;
}
Steve
|
|
|
|
|
this is really strange...even this is not opening file.
I created file named File.txt under C folder as you mentioned the path.
and with data as
abc,def,ghi
jkl,mno
pqr
stu,vw,xyz
But its not even opening the file. Reading the file is the next step. It should first open the file atleast....
Oh its giving me a heading now.
Thanks for your reply
|
|
|
|
|
The code I posted was also tested and worked for me. Nothing fancy is going on so I can't see why it doesn't work for you. Can you post the exact code you're using?
Steve
|
|
|
|
|
Hi
just now i tested it here at work and its working fine . I dont know whats wrong in my pc. May be my OS is not allowing it to read the file.
Can you think of any problem related to this.
Well i really need to sort this out at ma laptop. I wasted hell lotta time over this and the problem was something else. huh..
And yeh cn you also mention the command to hold the screen for output.
Well i am trying out with stystem("pause"); but it isnt working .
Is there any thing else for this.
Thanks a lot..
|
|
|
|
|
Software_Specialist wrote: I dont know whats wrong in my pc. May be my OS is not allowing it to read the file.
Can you think of any problem related to this.
Perhaps it's a security issue.
Software_Specialist wrote: And yeh cn you also mention the command to hold the screen for output.
I assume you're building a console app. One option is to use the Sleep function. e.g. Sleep(1000); to suspend the calling thread for one second. This function is in <windows.h> . Another option is to call _getch from <conio.h> to wait for a key press.
Steve
|
|
|
|
|
Hi All,
Looking for something that I hope is simple! Is there an index of "tmpstr" numbers that relate to the pocket pc platform, for reference to certain bits of info within the registry?
Example: To extract the Email Address that is entered in the device owner setup in the device, I would use (tmpStr[283])
or for the Phone Number within the owner setup (tmpStr[258])
I'm looking to extract the "Notes" info from
HKEY_CURRENT_USER\ControlPanel\Owner
Is there a master tmpstr index of numbers for this? Or can someone at least tell me what the value is for "Notes"
Thanks in advance, and sorry for my nubie approach!
BTW: Trying to program in evc++ 4.0
ZapMe1
|
|
|
|
|
How to get the active interfaces from the system. i am having both LAN and wirelss adapters but the lan is unplugged. how to get the active adapters in mfc
-- modified at 16:58 Saturday 24th March, 2007
Arise Awake Stop Not Till ur Goal is Reached.
|
|
|
|
|
What do you mean by "active"?
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
Hello,
My question is this.
How can I count the number of lines of code of my project?
I use Visual Studio.Is there any option?
Thanks
|
|
|
|
|
There are plug ins you can download, there is nothing build in
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
No, because I don't know what version you're using of visual studio. But, you know, and google will be happy to help you when you give it that info.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Visual Studio 2005
Yes,but what r the key words?
|
|
|
|
|
Someone shoot me.
Did you try searching code project for "line count" ?
http://www.codeproject.com/useritems/LineCounterAddin.asp[^]
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian, Christian. Turn the gun around and shoot him. Feel better now? I thought you would.
Software Zen: delete this;
|
|
|
|