|
Hope you may find the answer from this forum[^].
|
|
|
|
|
check events provided by flexgrid control!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
I have names of certain students and their ages stored in a text file
'records.txt'.
LIKE:
John 22
Paul 21
Sam 24
Harry 23
Now i want to store these ages and names in a structure 'records(r)' directly from the file. (Here i am not taking any input from the user)
as r.name & r.age.
Any clue to the solution???
|
|
|
|
|
I believe this query was answered
|
|
|
|
|
I couldn't get that. Plesae elaborate the clue so that i can learn a bit more.
I am trying to use the "isdigit" command for this purpose. Would that be suitable?
|
|
|
|
|
Dear Razanust,
I'll first suggess you not to create a new thread if you aren't satisfied with the answer.
Razanust wrote: couldn't get that. Plesae elaborate the clue so that i can learn a bit more.
I am trying to use the "isdigit" command for this purpose. Would that be suitable?
Now, as your file is a text file, First Clear whether you have stored it by formating by sprintf and then WriteFile etc or Writing the structure directly?
HARSH
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning.
modified on Tuesday, June 30, 2009 3:59 AM
|
|
|
|
|
Razanust wrote: Any clue to the solution???
1. Read the file line by line
2. use something like strtok to tokenize each line
3. fill the structure
|
|
|
|
|
I Don't know why u are trying there tipical methods.
Just Try the "C" way: -
struct MyStruct
{
char Name[20];
int age;
}
MyStruct myStruct;
FILE *pFile = fopen("Record.txt", "Wb+");
fwrite((char*)&myStruct, sizeof(MyStruct), 1, pFile);
and to reead :-
fread((char*)&myStruct, sizeof(MyStruct), 1, pFile);
HARSH
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning.
|
|
|
|
|
Harsh Shankar wrote: I Don't know why u are trying there tipical methods.
What?
|
|
|
|
|
Wouldn't it be easier to read and write the data in the file by my given way??
HARSH
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning.
modified on Tuesday, June 30, 2009 5:25 AM
|
|
|
|
|
I don't see anything in his post about writing the data back to a file. He only wants to read the file and store the tokens in a structure (or presumably an array of structures).
|
|
|
|
|
You need to open the file, read the contents, parse the read contents, store them into an array of structures.
Which part of this exercise are you having a problem with? And what have you done so far?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
supposing your use C language.may be this is a simply.You could use fscanf() function to realize it.You may find out the method of "fscanf()".
Like C++ more
|
|
|
|
|
Razanust wrote: Any clue to the solution???
Well, something like this comes to mind:
std::ifstream fin;
std::vector<Record> records;
fin.open("c:\\Records.txt");
std::copy(std::istream_iterator<Record>(fin), std::istream_iterator<Record>(), std::back_inserter(records));
fin.close(); Hint: you'll need to create the Record class.
"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, how to set an image as a background for dialog box or form in vc++?
Thanks in advance..
|
|
|
|
|
|
I wonder why your posting was down voted.
I have compensated it.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
void CClass::OnPaint()
{
CPaintDC dc(this); // device context for painting
CPaintDC dcc(this);
CRect rect;
GetClientRect(&rect);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap bmpBackground;
bmpBackground.LoadBitmap(IDB_BITMAP1);
//IDB_BITMAP1 is the image ID
BITMAP bitmap;
bmpBackground.GetBitmap(&bitmap);
CBitmap *pbmpOld=dcMem.SelectObject(&bmpBackground);
dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,
bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);
}
|
|
|
|
|
Hi,
I am wondering if anyone can help me out, i have created the following class and when i include it in another class it compiles fine, but when i try to create an object of it i get the following error:
1>Stocks.obj : error LNK2019: unresolved external symbol "public: __thiscall CStringParser::CStringParser(void)" (??0CStringParser@@QAE@XZ) referenced in function "public: __thiscall Stocks::Stocks(void)" (??0Stocks@@QAE@XZ)
1>Stocks.obj : error LNK2019: unresolved external symbol "public: __thiscall CStringParser::~CStringParser(void)" (??1CStringParser@@QAE@XZ) referenced in function "public: __thiscall Stocks::~Stocks(void)" (??1Stocks@@QAE@XZ)
In the file im calling this from i include the StringParser.h but still get this unresolved external symbol. Previously i have been including the .cpp files and it worked, but I want to learn how to do it properly using only header files. I am using Visual Studio 2008
Thanks in advance
#pragma once
#include <string>
#include <vector>
class CStringParser
{
public:
CStringParser::CStringParser();
CStringParser::~CStringParser();
std::vector<CString> CStringParser::ParseString(CString s, CString c);
};
#pragma once
#include "StringParser.h"
#include <string>
#include <vector>
CStringParser::CStringParser()
{
}
CStringParser::~CStringParser()
{
}
std::vector<CString> CStringParser::ParseString(CString s, CString c )
{
............
}
#pragma once
#include "StringParser.h"
class Test
{
public:
Test(void);
~Test(void);
private:
CStringParser sp;
};
|
|
|
|
|
Have you added StringParser.cpp to your project?
|
|
|
|
|
Member 4705538 wrote: Previously i have been including the .cpp files and it worked, but I want to learn how to do it properly using only header files.
What do you mean by previously include .cpp files?
Do you mean #include or include in the project?
You're most likely not including StringParser.cpp as part of the project.
If you don't, this file will not be compiled into an obj file.
The linker, when creating the executable will search for the functions(symbols) in the obj files.
And since StringParser.obj hasn't been created, it cannot find the constructor and destructor function definitions and so the errors.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Thanks for the replies, and yes i haven't included the cpp file into my project, do i just simply include it into any of my files that use the CStringParser or shall i include it in settings or stdafx.h?
|
|
|
|
|
Right click on the project name is solutions explorer and select add existing item.
Select StringParser.cpp
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Thanks for the quick reply again, i did that but then i got the following errors
1>c:\users\mc\documents\visual studio 2008\code snippets\visual c++\cstringparser.cpp(2) : warning C4627: '#include <string>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\mc\documents\visual studio 2008\code snippets\visual c++\cstringparser.cpp(3) : warning C4627: '#include <vector>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\mc\documents\visual studio 2008\code snippets\visual c++\cstringparser.cpp(4) : warning C4627: '#include "CStringParser.h"': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\mc\documents\visual studio 2008\code snippets\visual c++\cstringparser.cpp(48) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
I managed to fix the problem again by adding #include "CStringParser.cpp" to the Test.cpp file, but i was wondering if theres a way of only including the header files or something, but i guess ill stick to my way.
Thanks for the replies
|
|
|
|
|
Member 4705538 wrote: I managed to fix the problem again by adding #include "CStringParser.cpp" to the Test.cpp file
This is not the right way.
Look at the error message.
That is what you need to do.
Just ensure that #include <stdafx.h> is the first line in all .cpp files.
I guess you're missing that in StringParser.cpp.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|