-
July 31st, 2009, 04:07 PM
#1
Using Case Function To Read File Lines
Hello,
I want to build a program that read all the lines of a file and with some case functions. Here is a file example:
example.txt
And here is some example of case function:
Code:
case test:
cout << "Hello, World";
[...]
case example:
cout << "Enter a number: ";
cin >> number;
But i want that my program reads this sample file, read it's content and put the things that are in the case function in the screen(command line, in Linux: Terminal) in the order that is in the file.
Thanks,
Nathan Paulino Campos
-
August 1st, 2009, 12:41 AM
#2
Re: Using Case Function To Read File Lines
The simplest way is to compare string which you read from file with the string which you code in your program.
Your case function would something like this
Code:
void foo(std::string xStr)
{
if(xStr == "example")
//do something
else if(xStr == "test")
//do other thing
...
}
or you can use more complex and more cute method: read line from file, calculate its hash with some hash function and compare its hash with already coded hash in your application. Something like this:
Code:
void foo(size_t uiHash)
{
switch(uiHash)
{
case uiExampleHash:
//Do something
break;
...
};
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|