fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. int n;
  7. string str[n],temp;
  8.  
  9. for(int i =0;i<n;i++)
  10. {
  11. cin>>str[i];
  12.  
  13. }
  14.  
  15. for(int i =0;i<n-1;i++)
  16. {
  17.  
  18. for(int j = i+1;j<n;j++)
  19. {
  20. if(strcmp(str[i],str[j])>0)
  21. {
  22. strcpy(temp,str[i]);
  23. strcpy(str[i],str[j]);
  24. strcpy(str[j],temp);
  25. }
  26.  
  27. }
  28.  
  29. }
  30.  
  31.  
  32. for(int i = 0;i<n;i++)
  33. {
  34. cout<<str[i]<<endl;
  35. }
  36.  
  37.  
  38. return 0;
  39. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
3
bat
apple
batman
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:20:26: error: cannot convert ‘std::__cxx11::string’ {aka ‘std::__cxx11::basic_string<char>’} to ‘const char*’
           if(strcmp(str[i],str[j])>0)
                     ~~~~~^
In file included from /usr/include/c++/8/cstring:42,
                 from /usr/include/x86_64-linux-gnu/c++/8/bits/stdc++.h:48,
                 from prog.cpp:1:
/usr/include/string.h:136:32: note:   initializing argument 1 of ‘int strcmp(const char*, const char*)’
 extern int strcmp (const char *__s1, const char *__s2)
                    ~~~~~~~~~~~~^~~~
prog.cpp:22:13: error: cannot convert ‘std::__cxx11::string’ {aka ‘std::__cxx11::basic_string<char>’} to ‘char*’
      strcpy(temp,str[i]);
             ^~~~
In file included from /usr/include/features.h:446,
                 from /usr/include/x86_64-linux-gnu/c++/8/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/8/bits/c++config.h:508,
                 from /usr/include/c++/8/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/8/bits/stdc++.h:33,
                 from prog.cpp:1:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:88:1: note:   initializing argument 1 of ‘char* strcpy(char*, const char*)’
 __NTH (strcpy (char *__restrict __dest, const char *__restrict __src))
 ^~~~~
prog.cpp:23:18: error: cannot convert ‘std::__cxx11::string’ {aka ‘std::__cxx11::basic_string<char>’} to ‘char*’
      strcpy(str[i],str[j]);
             ~~~~~^
In file included from /usr/include/features.h:446,
                 from /usr/include/x86_64-linux-gnu/c++/8/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/8/bits/c++config.h:508,
                 from /usr/include/c++/8/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/8/bits/stdc++.h:33,
                 from prog.cpp:1:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:88:1: note:   initializing argument 1 of ‘char* strcpy(char*, const char*)’
 __NTH (strcpy (char *__restrict __dest, const char *__restrict __src))
 ^~~~~
prog.cpp:24:18: error: cannot convert ‘std::__cxx11::string’ {aka ‘std::__cxx11::basic_string<char>’} to ‘char*’
      strcpy(str[j],temp);
             ~~~~~^
In file included from /usr/include/features.h:446,
                 from /usr/include/x86_64-linux-gnu/c++/8/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/8/bits/c++config.h:508,
                 from /usr/include/c++/8/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/8/bits/stdc++.h:33,
                 from prog.cpp:1:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:88:1: note:   initializing argument 1 of ‘char* strcpy(char*, const char*)’
 __NTH (strcpy (char *__restrict __dest, const char *__restrict __src))
 ^~~~~
stdout
Standard output is empty