+ 2
Why i can't send char with array to the class?
ex: ma obj1(text[0]); ma is a class, text is string. there is a problem in conversion from char* to const char*
21 Respuestas
+ 2
@Kinshuk is right. So in your constructor definition you would have something like this:
public:
ma (const string& line) {
parseLine (line);
}
parseLine would be a function in the class that handles separating the string into individual chars.
+ 4
You may directly pass the string "237+6" into your constructor, and then iterate through your string to seperate the numbers and the operators inside their respective types.
It will be tedious to use different objects for the same.
+ 3
'\0' is used to terminate a string.
I didn't understand what you mean by 1 row input. Isn't:
234+7
a 1 row input?
+ 3
Which char? "237+6" is a string...
Edit - It is better to perform the elimination in the constructor itself. Creating numerous objects is a waste of memory.
+ 2
If the class constructor accepts a string (char*), there is no way you can use a char to initialize it.
text[0] is just a char, and is the first element/character in the string.
You need to pass text itself, or any other char* array.
+ 2
Pass the array text like this:
ma obj1(text);
+ 2
Then either you change your constructor's argument to a char, or pass your array element like this:
char cht[2]={text[0],'\0'};
ma obj1(cht);
+ 2
Then why do you need to use char? You need a string!
+ 1
so what should i do?
+ 1
i only need one by one char of that text
+ 1
what is \0 used for?
+ 1
yes
+ 1
in my mind, i ought to eliminate the input one by one
+ 1
so i need send the char to the class
+ 1
2,3,7,6 is a char
+ 1
and convert it with atoi()
+ 1
oke, i got something
+ 1
thanks for ur suggestions
0
@Kinshuk Vasisht:
actually i want to make "1 row input" calculator with classes
0
that's good idea, but i want do my own attempt