How to executing C++ programme -
i have simple c++ programme works fine on linux, when try execute on windows gives me this:
the ntvdm cpu hase encountered illegal instruction cs: 055 ip: 0185 op: of 00 00
this code of programme:
#include <iostream> using namespace std; int main() { int n; {cout<<"enter 2 or 3 : ";cin>>n;} while (n<2 || n>3); int b; cout<<"enter number of characters : ";cin>>b;cout<<endl; char t[b]; cout<<"enter characters : ";cin>>t;cout<<endl; string ta =t; if(n==2) { for(int r=0;r<b;r++){ for(int i=0;i<b;i++){ cout<<ta[r]<<ta[i]<<endl; } } } else { for(int r=0;r<b;r++){ for(int i=0;i<b;i++){ for(int k=0;k<b;k++) { cout<<ta[r]<<ta[i]<<ta[k]<<endl; } } } } cout<<"all right reserved ©"<<endl; return 0; }
apart fact variable length arrays not supported in iso c++ , presumably allowed here extension in gcc, start buffer overrun: array t should @ least t[b+1] long, , trusting user not enter more characters promised.
since assign t std::string (ta), why not read input directly ta intrinsically safe (not mention valid iso c++)?
string ta ; cout << "enter characters : " ; cin >> ta ;
Comments
Post a Comment