
please wait
Quest 1.cpp||In function 'int main()':| Quest 1.cpp|48|error: no matching function for call to 'getline(char [20], char [3])'| Quest 1.cpp|51|error: no matching function for call to 'getline(char [20], char [20])'| |
#include <iostream> #include <fstream> #include <cstring> #include <string> using namespace std; char first [20]; char last [20]; int firstlen; int lastlen; fstream data_store; char nfirst [3]; char nlast [20]; char lastone; char lasttwo; int main() { data_store.open("first.txt", ios::out); cout << "== Star Wars Name Generator ==" << endl; cout << "Enter first name" << endl; cin.getline (first, 20); data_store << first << endl; data_store.close(); firstlen = strlen (first); if (firstlen < 3) { cout << "First name must be at least three letters" << endl; } else { data_store.open("last.txt", ios::out); cout << "Enter last name" << endl; cin.getline (last, 20); data_store << last << endl; data_store.close(); lastlen = strlen (last); if (lastlen < 2) { cout << "Last name must be at least two letters" << endl; } else { data_store.open("first.txt", ios::in); getline(first, nfirst); data_store.close(); data_store.open("last.txt", ios::in); getline(last, nlast); data_store.close(); } } //cout << first << " " << last << endl; used to check array variables. not part of code cout << "Your Star Wars name is: " << nfirst << "-" << nlast << endl; } |
cin.getline()
takes a cstring, no problem there.getline()
takes a c++ string, first
is a cstring.
Quest 1.cpp||In function 'int main()':| Quest 1.cpp|48|error: invalid conversion from 'char*' to 'int'| Quest 1.cpp|48|error: initializing argument 2 of 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::getline(_CharT*, std::streamsize) [with _CharT = char, _Traits = std::char_traits<char>]'| Quest 1.cpp|51|error: invalid conversion from 'char*' to 'int'| Quest 1.cpp|51|error: initializing argument 2 of 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::getline(_CharT*, std::streamsize) [with _CharT = char, _Traits = std::char_traits<char>]'| ||=== Build finished: 4 errors, 0 warnings ===| |
first |
nfirst |
last |
nlast |
invalid conversion from char* to int |
#include <iostream> #include <fstream> #include <cstring> #include <string> using namespace std; char first [20]; char last [20]; int firstlen; int lastlen; fstream data_store; char nfirst [3]; char nlast [20]; char lastone; char lasttwo; int main() { data_store.open("first.txt", ios::out); cout << "== Star Wars Name Generator ==" << endl; cout << "Enter first name" << endl; cin.getline (first, 20); data_store << first << endl; data_store.close(); firstlen = strlen (first); if (firstlen < 3) { cout << "First name must be at least three letters" << endl; } else { data_store.open("last.txt", ios::out); cout << "Enter last name" << endl; cin.getline (last, 20); data_store << last << endl; data_store.close(); lastlen = strlen (last); if (lastlen < 2) { cout << "Last name must be at least two letters" << endl; } else { data_store.open("first.txt", ios::in); cin.getline(first, nfirst); data_store.close(); data_store.open("last.txt", ios::in); cin.getline(last, nlast); data_store.close(); } } //cout << first << " " << last << endl; used to check array variables. not part of code cout << "Your Star Wars name is: " << nfirst << "-" << nlast << endl; } |
#include <iostream> #include <fstream> #include <cstring> #include <string> using namespace std; char first [20]; char last [20]; int firstlen; int lastlen; fstream data_store; char nfirst [3]; char nlast [20]; char lastone; char lasttwo; int main() { data_store.open("first.txt", ios::out); cout << "== Star Wars Name Generator ==" << endl; cout << "Enter first name" << endl; cin.getline (first, 20); data_store << first << endl; data_store.close(); firstlen = strlen (first); if (firstlen < 3) { cout << "First name must be at least three letters" << endl; } else { data_store.open("last.txt", ios::out); cout << "Enter last name" << endl; cin.getline (last, 20); data_store << last << endl; data_store.close(); lastlen = strlen (last); if (lastlen < 2) { cout << "Last name must be at least two letters" << endl; } else { data_store.open("first.txt", ios::in); cin.getline(nfirst, 3); data_store.close(); data_store.open("last.txt", ios::in); cin.getline(nlast, 20); data_store.close(); } } //cout << first << " " << last << endl; used to check array variables. not part of code cout << "Your Star Wars name is: " << nfirst << "-" << nlast << endl; } |