Skip to content

Instantly share code, notes, and snippets.

@FabiolaRamirez
Created December 6, 2017 01:29
Show Gist options
  • Save FabiolaRamirez/38590364d7cb26c4dc1964eb0e65ef95 to your computer and use it in GitHub Desktop.
Save FabiolaRamirez/38590364d7cb26c4dc1964eb0e65ef95 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstring>
#include <string>
#include <stdio.h>
using namespace std;
int main(){
//C O P Y
//copy array de chars
const char* v[] = {"Esta","es","una","cadena","cualquiera"};
char aux[10];
strcpy( aux, v[0]);
cout << "strcpy( aux, v[0]) : " << aux << endl;
//copy strings
string str1 = "Hello";
string str2 = "Dany";
string str3;
str3 = str1;
cout << "str3 : " << str3 << endl;
//C O N C A T E N A T E
//array char
char a[] = "estoy";
char b[] = "feliz";
strcat(a,b);
cout << a << endl;
// string
string d = "estoy";
string e = "triste";
string f;
f = d + e;
cout << f << endl;
//L E N G H T
//array char
int len ;
char g[] = "dinosaurious";
len = strlen(g);
cout << len << endl;
//string
int len1;
string h = "hipopotamo";
len1 = h.size();
cout << len1 <<endl;
//C O M P A R E
//array char
//Returns 0 if s1 and s2 are the same; less than 0 if s1<s2; greater than 0 if s1>s2
char j[] = "dino";
char k[] = "dino";
char l [] = "perro";
int value;
value = strcmp(j,l);
cout << value << endl ;
//string
string m = "gato";
string n = "conejo";
if (m == n) {
cout << "son iguales";
} else {
cout << "no son iguales";
}
//G E T S T R I N G F R O M A S P E C I F I C C H A R
/*const char strx[] = "http://www.tutorialspoint.com";
const char chx = '.';
char *ret;
ret = strchr(strx, chx);
cout <<ret;*/
// FRONT return first character and BACK returns last charcter
// of string
string xx = "Hola pepito";
char ch_f = xx.front(); // Same as "ch_f = str6[0];"
char ch_b = xx.back(); // "ch_b = str6[str6.length() - 1];"
cout <<ch_f<<endl ;
cout <<ch_b<<endl ;
// c_str returns null terminated char array version of string
string str6 = "holitas";
const char* charstr = str6.c_str();
cout <<charstr<<endl;
// APPEND add the argument string at the end
string s = "estoy preocupada";
string s33 = "tomatodo";
s.append("yeah");
cout <<s<<endl;
s.append(s33,0,4);
cout <<s<<endl;
//FIND A STRING
//rerturn the position of chjaracter found if not negative if the char is not in the string
string yy = "estado";
int pp = yy.find('o');
cout <<pp<<endl;
// GETLINE() PUSH_BACK() POP_BACK()
string str;
// Taking string input using getline()
getline(cin,str);
cout << "The INPUT string: ";
cout << str << endl;
// Using push_back() to insert a character at end
str.push_back('s');
cout <<"pudhes char entered:"<< str << endl;
// Using pop_back() to delete a character from end
str.pop_back();
cout <<"deleted last char:"<< str << endl;
// R E S I Z E
string strP = "geeksforgeeks is for geeks";
strP.resize(13);
cout << strP << endl;
// Initializing string`
string stry = "geeksforgeeks";
// Declaring iterator
std::string::iterator it;
// Declaring reverse iterator
std::string::reverse_iterator it1;
// Displaying string
cout << "The string using forward iterators is : ";
for (it=stry.begin(); it!=stry.end(); it++)
cout << *it;
cout << endl;
// Displaying reverse string
cout << "The reverse string using reverse iterators is : ";
for (it1=stry.rbegin(); it1!=stry.rend(); it1++)
cout << *it1;
cout << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment