I am writing a programme for my circuit class that can find determinent of complex no. 3x3 matrix. for it i want complex input from user.. How to achieve..
I dont want to add real and imaginary parts separately...
i dont know if this is what you want, but if you want the user to input a number from the keyboard, you need to define the variable and use the cin command.
Example:
1 2 3 4 5 6 7 8 9 10
#include <iostream>
usingnamespace std;
void main()
{
int x;
cout << "Enter a number: ";
cin >> x;
}
Yes , you can use cin.getline() for string input . and atoi() can be used for conversion.
Check the sample code:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include<iostream>
#include<string>
#include<cstdlib>
usingnamespace std ;
int main(){
string s = "1+i3";
int index = s.find_first_of("+i");
int real = atoi(s.substr(0,index).c_str()) ;
int img = atoi(s.substr(index+2,3).c_str()) ;
cout << real << " " << img << endl;
return 0;
}