首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

初学者有关问题,救,c++字符串

2012-03-02 
菜鸟问题,急救,c++字符串读取一行文本,将所有4字单词替换成love,若4字单词开头字母是大写就替换成Love,然

菜鸟问题,急救,c++字符串
读取一行文本,将所有4字单词替换成love,若4字单词开头字母是大写就替换成Love,然后输出

[解决办法]
#include "stdafx.h "
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(){

ifstream infile;
infile.open( "temp.txt ");


char * str1 = new char[200];
string str;
char * temp;
infile.getline(str1,200);


temp = strtok(str1, ";., ");
while(temp != NULL)
{
string tempstr(temp);
if(tempstr.length() == 4)
{
if(*temp> 'Z ')
{
cout < < "love " < < endl;
str =str + "love ";
}
else
{
cout < < "Love " < < endl;
str = str + "Love ";
}
}
else
{
cout < < temp < < " " < < endl;
str = str + temp + " ";
}
temp = strtok(NULL, ";., ");
}

cout < < str < < endl;
}

热点排行