Wonder if anyone can tell me what I'm getting wrong on this.
I keep getting errors on the last line:
26 37 C:\Users\DSNoS\Documents\CPP Projects\Address\main.cpp [Error] expected primary-expression before 'address_work_string'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <iostream>
#include <string>
using namespace std;
string pop_first_word(string &remaining_address, string delim){
int position = remaining_address.find(delim);
string first_word = remaining_address.substr(0,position);
remaining_address = remaining_address.substr(position+1);
return first_word;
}
int main(){
string delim = " ";
string address_string = "PO Box 820 and more and more";
string remaining_address;
string address_work_string = address_string;
string first_word="";
first_word = pop_first_word(string address_work_string, string delim);
}
|
Thanks in advance for your help.
Last edited on
first_word = pop_first_word(string address_work_string, string delim);
This is not how to call a function. The bits in bold have no business being there. I expect you meant this:
first_word = pop_first_word(address_work_string, delim);
Thank you. That worked. I ended up doing it the way I did because in other places it was making me call out the variable data type.
When you declare and define functions, you specify the data type.
When you're actually using them, you do not.