Programming Exercise 7-9 D & Ⓡ CENGAGE MINDTAP O Tasks Input Output sh: 1: pause: not found Results Ⓒ Jason Brian Miller
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Programming Exercise 7-9 D & Ⓡ CENGAGE MINDTAP O Tasks Input Output sh: 1: pause: not found Results Ⓒ Jason Brian Miller
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void getName();
int main() {
getName();
system("pause");
return 0;
}
void getName() {
string fullName, lastName, firstName;
int commaPos, otherJunk;
ifstream inData;
inData.open("Ch7.Ex9Data.TXT");
while (getline(inData, fullName)) {
commaPos = fullName.find(",");
// Substring for lastName
lastName = fullName.substr(0, commaPos);
// Substring from commaPos + 2 to end
firstName = fullName.substr(commaPos + 2);
cout << firstName << " " << lastName <<endl;
}
}
Programming Exercise 7-9 D & Ⓡ CENGAGE MINDTAP O Tasks Input Output sh: 1: pause: not found Results Ⓒ Jason Brian Miller Lisa Maria Blair Anil Kumar Gupta Sumit Sahil Arora Rhonda Beth Saleh Brody Spilner Expected Output → Jason Brian Miller Lisa Maria Blair Anil Kumar Gupta Sumit Sahil Arora Rhonda Beth Saleh Brody Spilner 0 Run checks Submit 0% Ch7_Ex9Data.txt 4 using namespace std; 5 6 void getName(); 7 8 int main() { 9 getName(); main.cpp 16 17 18 19 20 21 22 23 24 25 26 27} system("pause"); return 0; 10 11 12 } 13 14 void getName() { 15 string fullName, lastName, firstName; int commaPos, other Junk; ifstream inData; + inData.open("Ch7.Ex9Data.TXT"); while (getline(inData, fullName)) { commaPos = fullName.find(","); // Substring for lastName ■ ↓ lastName = fullName.substr(0, commaPos); // Substring from commaPos + 2 to end firstName= fullName.substr(commaPos + 2); cout << firstName << " " << lastName << endl; } > Terminal sandbox $ Q Search this course X + A-Z