Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <string> //if you want to do the new school way you need to include the string library as it will allow you to use strings
  3.  
  4. /*also if you want to do the new school way you will need to put using
  5. namespace::std at the beginning of the source file, i generally put it
  6. right after i declare my header files. This will allow you to use things
  7. like endl, cin, cout, etc... without having to type out std::cout, std::cin, etc..*/
  8.  
  9. //also remember to remove the comment lines for whichever method you wish to use
  10.  
  11. int main(){
  12. /*
  13. //new school way using strings
  14.  
  15. std::string a; //declare a string variable
  16. std::cout<<"Enter a file name you wish to use then press enter:"; //tell the user what you want them to do
  17. std::cin>>a; //take user input and store it in the string variable you declared earlier
  18. std::endl;//add a new line character to tidy up a bit
  19. */
  20.  
  21. //==============================================================================================================
  22.  
  23.  
  24.  
  25. //old school way of managing strings and it also allows you to put a limit on how big the name can be
  26.  
  27.  
  28. //int a=3; //this value will determine the max number of characters the string will store but you always must
  29. //account for the \0. So for example if you want something to hold 3 characters the limiter or the variable
  30. //b in this case will have to be at least 4.
  31.  
  32.  
  33. //char b[a]; //here we made a character array. b represents the array itself while a represents the individual characters in the array
  34. //std::cout<<"Enter a name (only the first 2 letters will be stored) then press enter:";//tell the user what to do
  35. //std::cin.get(b,a);//cin in this case tell the computer to store the value into b and get tells the computer to get the amount to store
  36. //std::endl(std::cout);//tidies up the output by starting at a new line you need to use this format when using the old school method after using cin
  37. //std::cout<<b;//outputs the array b
  38. return 0;
  39. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement