我需要只能使用C++字符串来改变下面的输入段落。我遇到的问题是,当我在最后插入标点符号的时候,比如“程序”,它将它分别作为“程序”而不是“程序”和“ - ”分别放入我的数组中。我需要知道如何做到这一点,以便我可以用“。”替换所有的“ - ”。C++字符串,标点符号,数组
某人如何区分这两者并将它们分别放置在阵列中自己的块中?
#include <iostream>
#include <fstream>
using namespace std;
void read(string line[], string para[], int &d)
{
string temp;
int i = 0;
ifstream myfile ("paragraphwordsub.txt");
if (myfile.is_open())
{
while (temp != "$")
{
myfile >> temp;
line [i] = temp;
cout << line[i] << " ";
i++;
}
cout << endl;
i=0;
while (!myfile.eof())
{
myfile >> temp;
para[i] = temp;
cout << para[i] << " ";
d++;
i++;
}
myfile.close();
}
else cout << "Unable to open file";
cout << endl << endl << i << endl << para[73] << endl;
return;
}
int main()
{
int const SIZE = 100;
string a [SIZE];
string b [SIZE];
int counter = 0;
read(a, b, counter);
cout << endl << endl << counter << endl;
return 0;
}
输入:
谁的程序是这样的? 有重要的节目要做,汤米被要求做这样的 - 汤米相信山姆会这样做 - 参孙可以做到这一点,但尼科尔森这样做 - 山姆对此感到愤怒,因为 这样的汤米的节目 - 汤米以为参孙可以做到这样,但 Nicholsonnders意识到,汤米不会做such-它结束了那 汤米指责山姆时Nicholsonnders做了什么参孙可以有私下作出─
我喜欢示例文本没有意义。 –
你可以使用'isalpha'函数来检查一个字符是否是字母。 –
示例文本应该是没有意义的,因为我将用不同的文本替换其中的文本。这包括将所有“ - ”改为“”。尼尔,我不知道我会如何使用字符串并从文件中拉出它。 – Limit