| | |
Need help to create a main driver in c++
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 7
Reputation:
Solved Threads: 0
Dear All
I would be very happy if you could help me!
I need to create a main() program which is be able to;
* reads in a list of words and their associated meanings from the
given test file(file.txt)(This file contains 10 lines)
* provide an interactive menu interface to find a ‘word’ and display
the meaning(s) of the searched ‘word’ if it exists. Make sure you
include all appropriate input data validation at the menu interface
and provide suitable messages for a successful or unsuccessful
search.
I need a scratch main program to get the idea of how to create a main driver function.
regards
Juniper
I would be very happy if you could help me!
I need to create a main() program which is be able to;
* reads in a list of words and their associated meanings from the
given test file(file.txt)(This file contains 10 lines)
* provide an interactive menu interface to find a ‘word’ and display
the meaning(s) of the searched ‘word’ if it exists. Make sure you
include all appropriate input data validation at the menu interface
and provide suitable messages for a successful or unsuccessful
search.
I need a scratch main program to get the idea of how to create a main driver function.
regards
Juniper
•
•
Join Date: Jan 2008
Posts: 3,819
Reputation:
Solved Threads: 501
0
#2 29 Days Ago
C++ Syntax (Toggle Plain Text)
// outline // #include statements here // #define statements here // global variables here // function declarations here int main (int argc, char* argv[]) { // variables local to main () // more code return 0; } // functions go here
This is a vague skeleton. You're going to have to show some effort or ask a more specific question for a more detailed answer.
0
#4 28 Days Ago
•
•
•
•
Thanks
But still I dont get that how to read the lines(string) from an external file " file.txt"
regards
C++ Syntax (Toggle Plain Text)
#include <fstream> // Header File for File Reading #include <iostream> // Header File for General I/O-put #include <string> // Header File for Strings using namespace std; // Use namespacing char String[1024]; // Create a string as a global var bool LoadString() // Function for loading the string { ifstream in ("String.dat"); // Start Loading data from b.dat if (in.good()) // If the file is loadable (existing) { in >> String; // Load the string return true; } else // If the file is unloadable (nonexisting) { in.close(); // Stop Loading data form String.dat cout << "Could not load the file!" << endl; // Post error message system("PAUSE"); // Pause, to make the user able to read the error message return false; // Exit the program } in.close(); // Stop Loading data form String.dat } int main() { if (!LoadString()){return 0;} // If the function returned cout << "The length of String is " << StringLength() << " characters.\n" << endl; // Post the length system("PAUSE"); // Pause, to make the user able to read the error message return 0; // Exit the program }
And an example for two Strings, just made using copypaste:
C++ Syntax (Toggle Plain Text)
#include <fstream> // Header File for File Reading #include <iostream> // Header File for General I/O-put #include <string> // Header File for Strings using namespace std; // Use namespacing char String[1024]; // Create a string as a global var bool LoadString() // Function for loading the string { ifstream in ("String.dat"); // Start Loading data from b.dat if (in.good()) // If the file is loadable (existing) { in >> String; // Load the string return true; } else // If the file is unloadable (nonexisting) { in.close(); // Stop Loading data form String.dat cout << "Could not load the file!" << endl; // Post error message system("PAUSE"); // Pause, to make the user able to read the error message return false; // Exit the program } in.close(); // Stop Loading data form String.dat } bool LoadString2() // Function for loading the string { ifstream in ("String.dat"); // Start Loading data from b.dat if (in.good()) // If the file is loadable (existing) { char Line1[1024]; in >> Line1 >> String; // Load the second string return true; } else // If the file is unloadable (nonexisting) { in.close(); // Stop Loading data form String.dat cout << "Could not load the file!" << endl; // Post error message system("PAUSE"); // Pause, to make the user able to read the error message return false; // Exit the program } in.close(); // Stop Loading data form String.dat } int StringLength() // Function for finding the stirng length { string str (String); // set str return str.length(); // return the length of the string } int main() { if (!LoadString()){return 0;} // If the function returned cout << "The length of String is " << StringLength() << " characters.\n" << endl; // Post the length if (!LoadString2()){return 0;} // If the function returned cout << "The length of String is " << StringLength() << " characters.\n" << endl; // Post the length system("PAUSE"); // Pause, to make the user able to read the error message return 0; // Exit the program }
Last edited by Skeen; 28 Days Ago at 5:38 pm.
// Skeen
![]() |
Similar Threads
- How to install JDBC Driver for MSSQL ? (JSP)
- Linker Error (C++)
- passing data to a program (C++)
- I want to learn - How to create and use objects. (C#)
- Boot Disks (Viruses, Spyware and other Nasties)
- Main Options / Style Questions (C++)
- problems with bufferedImage (Java)
Other Threads in the C++ Forum
- Previous Thread: New to this and need help, please
- Next Thread: Help with "simple for some" c++ output problem..
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






