I am very new to c++, previously I used to program in Python. I am learning how to define a
function in c++, I assume it is a bit like the python def
function. I keep getting the error:
no match for call to `(std::string) (const char[4])`.
I am using dev c++. Here is my code:
#include <iostream>
int main()
{
using namespace std;
cout << "Enter a number: "; // ask user for a number
int x;
cin >> x; // read number from console and store it in x
cout << "You entered " << x << endl;
cout << "\n" << "Enter 'a': ";
string y;
cin >> y;
if (y=="a"){
cout << "You typed 'a'!!!";
int z;
cin >> z;
return 0;
}
else {
cout << "You didn't type 'a'!!!" << endl;
}
string word;
string subfunction(word);
{
cout << word << endl;
}
subfunction("abc");
return main();
}
At the end, you might have noticed the declaration and definition of subfunction
. If I was writing this in python it would be:
def subfunction(word):
print(word)
subfunction('abc')