本文介绍了我遇到了字符串方法的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我制作了这个代码,它应该接收一串Last,First MI,它应该在First MI Last中返回它。它应该通过引用调用来读取它并按值调用返回它。
它还应该分隔last,first和MI的值。并使用find()取出逗号,然后将它们连接起来
这就是我所拥有但我得到的编译错误
I made this code that is supposed to receive a string of "Last, First MI" and it's supposed to return it in "First MI Last". It's supposed to read it using call by reference and return it on call by value.
It is also supposed to separate the values of last, first, and MI. and use find() to take out the commas and then concatenate them back up
This is what I have but I'm getting a compile error
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
void inputData(string &); //Declare Call-by-reference function
void outputData(string); //Declare Call-by-value function
int main() {
string myString;
inputData(myString);
outputData(myString);
}
void inputData(string &myString) {
cout << "Last, First, MI : ";
getline( cin, myString );
istringstream parse( myString );
string first, mi, last, fullname;
int index;
index = myString.find_last_of(' ');
last = myString.substring(0, index);
mi = myString.substring(index+1, index);
first = myString.substring(index+1);
fullname = first + mi + last;
cout << fullname << " by reference " << endl; //Pass-by-reference*
}
void outputData(string myString) {
cout << myString << " by value " << endl; //Pass-by-value
}
错误在
error is on
last = myString.substring(0, index);
mi = myString.substring(index+1, index);
first = myString.substring(index+1);
错误是
error is
In function 'void inputData(std::string&)':|
|25|error: 'struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >' has no member named 'substring'|
|26|error: 'struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >' has no member named 'substring'|
|27|error: 'struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >' has no member named 'substring'|
||=== Build finished: 3 errors, 0 warnings ===|
提前谢谢,
对不起,
谢谢
Thanks in advance,
sorry,
Thanks
推荐答案
这篇关于我遇到了字符串方法的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!