Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. //skriv till
  2. int main()
  3. {
  4. int rows;
  5. string fileName;
  6. ofstream outfile;
  7. cout << "Enter number of rows: ";
  8. cin >> rows;
  9. cout << "Enter the file name: ";
  10. cin >> fileName;
  11.  
  12. outfile.open("C:\\Users\\elvir\\Desktop\\IoT\\C++\\Labbar\\" + fileName + ".txt", ofstream::out | ofstream::app);
  13. string newline;
  14. for (int i = 0; i < rows; i++)
  15. {
  16. cout << "Enter line " << i + 1 << ": ";
  17. cin.ignore();
  18. getline(cin, newline);
  19. outfile << newline << endl;
  20. }
  21. outfile.close();
  22. }
  23.  
  24. // slå ihop
  25. int main()
  26. {
  27. string fileName1, fileName2, fileName3;
  28. cout << "Enter the first file name: ";
  29. cin >> fileName1;
  30. cout << "Enter the second file name: ";
  31. cin >> fileName2;
  32. cout << "Enter the third file name: ";
  33. cin >> fileName3;
  34. ofstream outfile;
  35. ifstream infile1, infile2;
  36. outfile.open("C:\\Users\\elvir\\Desktop\\IoT\\C++\\Labbar\\" + fileName1 + ".txt", ofstream::out | ofstream::app);
  37. infile1.open("C:\\Users\\elvir\\Desktop\\IoT\\C++\\Labbar\\" + fileName2 + ".txt", ifstream::in);
  38. string line;
  39. while (!infile1.eof())
  40. {
  41. getline(infile1, line);
  42. outfile << line << endl;
  43. }
  44. infile1.close();
  45. infile2.open("C:\\Users\\elvir\\Desktop\\IoT\\C++\\Labbar\\" + fileName3 + ".txt", ifstream::in);
  46. while (!infile2.eof())
  47. {
  48. getline(infile2, line);
  49. outfile << line << endl;
  50. }
  51. infile2.close();
  52. outfile.close();
  53. }
  54.  
  55. //To lower
  56. int main()
  57. {
  58. ofstream outfile;
  59. ifstream infile;
  60. outfile.open("C:\\Users\\elvir\\Desktop\\IoT\\C++\\Labbar\\lower.txt", ofstream::out | ofstream::app);
  61. infile.open("C:\\Users\\elvir\\Desktop\\IoT\\C++\\Labbar\\test1.txt", ifstream::in);
  62. string line;
  63. while (!infile.eof())
  64. {
  65. getline(infile, line);
  66. for (char ch : line)
  67. {
  68. ch = tolower(ch);
  69. outfile << ch;
  70. }
  71. outfile << "\n";
  72. }
  73. }
  74.  
  75. //To lower del två
  76. int main()
  77. {
  78. vector<char> vowelList = { 'a', 'e', 'i', 'o', 'u', 'y' };
  79. ofstream outfile;
  80. ifstream infile;
  81. outfile.open("C:\\Users\\elvir\\Desktop\\IoT\\C++\\Labbar\\vowelUpper.txt", ofstream::out | ofstream::app);
  82. infile.open("C:\\Users\\elvir\\Desktop\\IoT\\C++\\Labbar\\lower.txt", ifstream::in);
  83. string line;
  84. while (!infile.eof())
  85. {
  86. getline(infile, line);
  87. for (char ch : line)
  88. {
  89. if (find(vowelList.begin(), vowelList.end(), ch) != vowelList.end())
  90. {
  91. ch = toupper(ch);
  92. outfile << ch;
  93. }
  94. else
  95. {
  96. outfile << ch;
  97. }
  98. }
  99. outfile << "\n";
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement