| | |
first cannot conver std::string to const char, now runtime error!
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
C++ Syntax (Toggle Plain Text)
cin.ignore(); cout << "Enter lecture notes/tutorials location.\n"; cout << "e.g C:/Lecture Notes/lecture01.ppt"; cout << ">>>"; getline(cin,lectut_loca); cout << "Enter lecture notes/tutorials name: "; cout << "e.g lecture01.ppt"; cout << ">>>"; getline(cin,lectut_name); string copy = "copy"; copier = copy + " " + lectut_loca + " " + lectut_name; const char *copier; cout << copier; getch(); system(copier); cout << "\nLecture notes/tutorials added.";
the const char *copier; i use copier = copier.c_str(); but get error on system(copier); when compiling. then i use const char *copier; no error compile but runtime error!
:lol:
what should i do?
•
•
•
•
what should i do?cin.ignore(); cout << "Enter lecture notes/tutorials location.\n"; cout << "e.g C:/Lecture Notes/lecture01.ppt"; cout << ">>>"; getline(cin,lectut_loca); cout << "Enter lecture notes/tutorials name: "; cout << "e.g lecture01.ppt"; cout << ">>>"; getline(cin,lectut_name); string copy = "copy"; copier = copy + " " + lectut_loca + " " + lectut_name; // using variable before declaring it is not allowed in your case copier. const char *copier; // initialisation of const variables must be done // during declaration intself eg. const int i = 8 ; cout << copier; getch(); // getch() is non portable use cin.get () system(copier); cout << "\nLecture notes/tutorials added.";
And maybe you should look at this simple expample.
C++ Syntax (Toggle Plain Text)
string my_copy = "copy" ; my_copy += " " + lectut_loca + " " + lectut_name ; const char* copier = my_copy.c_str() ; system (copier) ;
Hope ti helped, bye.
PS: looks like you are trying to implement the copy function of DOS.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
•
•
•
•
Look at the things i have mentioned above.
And maybe you should look at this simple expample.
Hope ti helped, bye.C++ Syntax (Toggle Plain Text)
string my_copy = "copy" ; my_copy += " " + lectut_loca + " " + lectut_name ; const char* copier = my_copy.c_str() ; system (copier) ;
PS: looks like you are trying to implement the copy function of DOS.
yah.. should be like that? urmm.. syntax error!
Error messages come with line numbers.
Use those line numbers to find out where in the code the problem is. Any editor should have a "goto line" feature, or at least display line numbers in some manner.
Post code (annotated with line numbers if necessary) along with exact error messages if you're still stuck.
Use those line numbers to find out where in the code the problem is. Any editor should have a "goto line" feature, or at least display line numbers in some manner.
Post code (annotated with line numbers if necessary) along with exact error messages if you're still stuck.
•
•
•
•
add
char a='"';
strcat(a, copier);
strcat(copier, a);
hahaha.. compile error!
strcat funtion expects you to supply both parameters as char* ie char pointers and you supplying it a char.You can get its prototype here: http://www.cppreference.com
Post your complete program from start to finish with the header files and then maybe i could pinpoint the mistake.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
the staff module...
and the staff header
C++ Syntax (Toggle Plain Text)
//the staff module #include "staff.h" #include <iostream> #include <fstream> #include <cstring> using namespace std; class sfunction { private: string lectut_loca; string lectut_id; string lectut_name; string announce_id; string announce_subject; string announce_desc; public: void add_lec_tut() { string copier; display_title("Add Lecture Notes/Tutorials"); cout << "Please enter course id: "; cin >> lectut_id; for(int i=1; i<=count_line("course.MOLS"); i++) { if(gettok( read("course.MOLS", i), ';', 1) == lectut_id) { cin.ignore(); cout << "Enter lecture notes/tutorials location.\n"; cout << "e.g C:/Lecture Notes/lecture01.ppt"; cout << ">>>"; getline(cin,lectut_loca); cout << "Enter lecture notes/tutorials name: "; cout << "e.g lecture01.ppt"; cout << ">>>"; getline(cin,lectut_name); string my_copy = "copy" ; my_copy += " " + lectut_loca + " " + lectut_name ; const char* copier = my_copy.c_str() ; cout << copier; system(copier); cin.get(); cout << "\nLecture notes/tutorials added."; getch(); break; } else if(i==count_line("course.MOLS")) { cout << lectut_id << " not found!"; getch(); } } getch(); }; void edit_lec_tut() { display_title("Edit Lecture Notes/Tutorials"); getch(); }; void del_lec_tut(){}; void add_announ()//add announcement(s) { display_title("Add Announcements"); cout << "Please enter course id: "; cin >> announce_subject; for(int i=1; i<=count_line("course.MOLS"); i++) { if(gettok( read("course.MOLS", i), ';', 1) == announce_subject) { cout << "Plase enter announcement id: "; cin >> announce_id; cin.ignore(); cout << "Please enter your announcement: "; getline(cin,announce_desc); write("Lecturer/announcement.MOLS", i, announce_id + ";" + announce_subject + ";" + announce_desc); cout << "\nAnnouncement added."; getch(); break; } else if(i==count_line("course.MOLS")) { cout << announce_subject << " not found!"; getch(); } } }; void edit_announ() { display_title("Add Announcements"); cout << "Enter course id: "; cin >> announce_subject; for(int i=1; i<=count_line("Lecturer/announcement.MOLS"); i++) { if(gettok( read("Lecturer/announcement.MOLS", i), ';', 2) == announce_subject) { cout << "Previous announcement:\n" << gettok( read("Lecturer/announcement.MOLS", i), ';', 3) << endl; cout << "\nEnter new announcement id: "; cin >> announce_id; cin.ignore(); cout << "Enter new announcement: "; getline(cin,announce_desc); write("Lecturer/announcement.MOLS", i, announce_id + ";" + announce_subject + ";" + announce_desc); cout << "\nAnnouncement added."; getch(); break; } else if(i==count_line("Lecturer/announcement.MOLS")) { cout << announce_subject << " not found!"; getch(); } } }; void del_announ() { display_title("Delete Announcements"); cout << "Enter announcement id: "; cin >> announce_id; for(int i=1; i<=count_line("Lecturer/announcement.MOLS"); i++) { if(gettok( read("Lecturer/announcement.MOLS", i), ';', 1) == announce_id) { del("Lecturer/announcement.MOLS", i); cout << "Announcement succesfully deleted!"; getch(); } } }; void add_assign(){}; void edit_assign(){}; void del_assign(){}; };
and the staff header
C++ Syntax (Toggle Plain Text)
#ifndef _STAFF_H_ #define _STAFF_H_ #include "staff.cpp" #endif
So where is your
int main (void) function and what problems are you facing with this code, and if facing compile time problems mark the line which flags the error in red so taht we can see it and if run time error then describe it. I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Newbie in need of help!!!
- Next Thread: setprecision
| Thread Tools | Search this Thread |
Tag cloud for C++
api array arrays based beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines linker list loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference return rpg search simple spoonfeeding string strings struct temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






