fstream problem,c++ newbies need help.... how to rewrite my code and

fstream ( ifstream ) problem .. need help rewrite code

Page 1 of 1

3 Replies - 844 Views - Last Post: 02 November 2009 - 09:19 AM Rate Topic: -----

#1 sibobo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-November 09

fstream problem,c++ newbies need help.... how to rewrite my code and

Posted 02 November 2009 - 08:30 AM

#include <iostream>
#include <string>
using namespace std;

void main()
{
	int status[26]; 
	string kod[27]; [color="#33CC00"]// this is the element that i need to store in .text file and retrieve using ifstream... i fail to use the ifstream fuction hence cant retrieve the all the kod[27] data to be use from .text file[/color]

	string alpha[27]; 
	string human[100]; 
	string temp; 
	char ans; 
	int i,jump,cool,ulang,hold; 
	for(int A=0;A<26;A++)
	{
		alpha[A]="A";               
		A++;
	}
	alpha[26]=' '; 
	[color="#33CC00"]kod[0]=".-";
	kod[1]="-...";
	kod[2]="-.-/>.";
	kod[3]="-..";
	kod[4]=".";
	kod[5]="..-";
	kod[6]="----";
	kod[7]="....";
	kod[8]="..";
	kod[9]=".----";
	kod[10]="-.-/>";
	kod[11]=".-..";
	kod[12]="--";
	kod[13]="-.";
	kod[14]="---";
	kod[15]=".--.";
	kod[16]="--.-/>";
	kod[17]=".-.";
	kod[18]="...";
	kod[19]="-";
	kod[20]="..-";
	kod[21]="...-";
	kod[22]=".--";
	kod[23]="-..-";
	kod[24]="-.-/>-";
	kod[25]="--..";
	kod[26]="~";[/color][size=6]
	
	do
	{
		for(int yo=0;yo<26;yo++)
		{
			status[yo]=0;          
		}
		ulang=0; 
		cool=0; 
		system("cls"); 
		cout<<"\n\t<Symbol '/' to stop >"; 
		cout<<"\n\n\t Insert the code Morse :\t"; 
		for(i=0;i<100;i++)
		{
			cin>>temp;
			if(temp=="/") 
			{
				break;
			}
			else
			{
				human[i]=temp; 
			}
		}
		
		cout<<"\n\tHasil          :\t";
		
		for(int j=0;j<i;j++)
		{
			jump=0; 
			
			for(int t=0;t<27;t++)
			{
				
				if(human[j]==kod[t])
				{
					cout<<alpha[t]<<' '; 
					jump++; 
					if(human[j]!="~")
					{
						status[t]++; 
						cool++; 
					}
				}
			}
			
			if(jump==0)
			{
				cout<<"? ";
			}
		}
		
		cout<<"\n\n\t number of alphabet had been used : "<<cool<<" alphabet";
		cout<<"\n\n\tnumber of repeated alphabet :-\n";
		hold=0; 
		for(int fke=0;fke<26;fke++) 
		{
			if(status[fke]>1)
			{
				hold++; 
				cout<<"\n\t\t Alphabet "<<alpha[fke]<<", repeated "<<status[fke]<<" times..";
			}
		}
	
		cout<<"\n\n\t Number of repeated alphabet : "<<hold<<" alphabet";
		cout<<"\n\n\tContinue ? (y/n)\t"; 
		cin>>ans;
	}while(ans=='y'||ans=='Y'); 

	cout<<"\n\n";
}


*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 02 November 2009 - 08:36 AM


Is This A Good Question/Topic? 0
  • +

Replies To: fstream problem,c++ newbies need help.... how to rewrite my code and

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: fstream problem,c++ newbies need help.... how to rewrite my code and

Posted 02 November 2009 - 08:37 AM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#3 sibobo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-November 09

Re: fstream problem,c++ newbies need help.... how to rewrite my code and

Posted 02 November 2009 - 08:37 AM

i put all the element that i've highligt in text file which i name codemorse.txt that i've save in the same file which i save this c++ code..... but i still cant retrieve it using ifstream and too many error when i try to use the ifstream....

realy need help
Was This Post Helpful? 0
  • +
  • -

#4 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1330
  • View blog
  • Posts: 4,561
  • Joined: 19-February 09

Re: fstream problem,c++ newbies need help.... how to rewrite my code and

Posted 02 November 2009 - 09:19 AM

Couple of things I have noticed.

A should be incremented how often.
	for(int A=0;A<26;A++)
	{
		alpha[A]="A";			   
		A++;
	}



	kod[26]="~";
				...
				...
			if(temp=="/") 
			{


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1