33,311
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> result;
ifstream inFile("text");
if(inFile == 0)
{
cout << "fail to open file text" << endl;
return 1;
}
string word;
string temp;
while(!inFile.eof())
{
getline(inFile, temp);
for(int k = 0; k < temp.size(); k++)
{
if((temp[k] >= 'A' && temp[k] <= 'Z') || (temp[k] >= 'a' && temp[k] <= 'z'))
word += temp[k];
else
if(!word.empty())
{
result.push_back(word);
word = "";
}
}
}
for(vector<string>::iterator iter = result.begin(); iter != result.end(); ++iter)
cout << *iter << endl;
return 0;
}
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> result;
ifstream inFile("text");
if(inFile == 0)
{
cout << "fail to open file text" << endl;
return 1;
}
string word;
string temp;
while(!inFile.eof())
{
getline(inFile, temp);
for(int k = 0; k < temp.size(); k++)
{
if((temp[k] >= 'A' && temp[k] <= 'Z') || (temp[k] >= 'a' && temp[k] <= 'z'))
word += temp[k];
else
if(!word.empty())
{
result.push_back(word);
word = "";
}
}
}
for(vector<string>::iterator iter = result.begin(); iter != result.end(); ++iter)
cout << *iter << endl;
return 0;
}
#include<iostream>
#include <fstream>
using namespace std;
char str[]="hello this is a c programe!n"
"i know this difference n"
"and mocive";
ofstream outfile ("data.txt");
for(int i=0;i<strlen(str);i)
outfile.put(str[i]);
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
char str[][50] = {"hello this is a c programe!n", "i know this difference n", "and mocive"};
int main()
{
ofstream outfile ("data.txt");
for(int k = 0; k < 3; k++)
for(int i=0;i< strlen(str[k]);i++)
outfile.put(str[k][i]);
outfile.close();
return 0;
}
#include<iostream>
#include<string>
using std::cout;
using std::endl;
using std::cin;
using std::string;
int main(void)
{
string str[10000];
int i=0;
for(;;i++)
{
getline(cin,str[i],' ');
cout<<str[i]<<endl;
}
return 1;
}
#include<iostream>
#include<stdio.h>
using std::cout;
using std::cin;
using std::endl;
int main(void)
{
char word[10000],*ptr[1000]={NULL};
int i=0,j=0;
cout<<"Please input a string:"<<endl;
gets(word);
cout<<"The result is:"<<endl;
while(word[i]==' ')
i++;
ptr[j]=&word[i];
j++;
while(word[i])
{
if(word[i]==' ')
{
word[i]='\0';
if(word[i+1]&&word[i+1]!=' ')
{
ptr[j]=&word[i+1];
j++;
}
}
i++;
}
for(i=0;i<j;i++)
cout<<ptr[i]<<endl;
}