Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
C++
#include<iostream>
#include<string>


using namespace std;
char PrintCharacter(char);

char PrintCharacter(char sWord){
	 

char cAlp[]={"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"};
char cAl[]= {"YPLTAVKREZGMSHUBXNCDIJFQOWypltavkrezgmshubxncdijfqow"};       

for(int i=0;i<52;i++){
	if(sWord!=cAlp[i])
	continue;
	else
	cout << cAl[i];
}

}



int main(){
string sSent;
sSent = "How do I do this";

	int iLength = sSent.length();
	
	for(int iStart=0;iStart<ilength;istart++){>
		if(isalpha(sSent[iStart]))
		PrintCharacter(sSent[iStart]);
		else
		cout <<sSent[iStart];
		}

/* y p l t a v k r e z g m s h u b x n c d i j f q o w */		
 
}



in this code, im translating the sentence "How do I do this"
to Ruf tu E tu drec <--- in al bhedizers.


so my problem is that the sentence is in inside .cpp
we were tasked to make the sentence inside a .txt file then the program will read it and output in also in a .txt file.

is there a way to do that?? i read some on how but I dont understand how to apply it.
sorry for noob questions.
Posted
Updated 18-Feb-15 21:31pm
v5
Comments
Andy411 19-Feb-15 3:31am    
Did you try something like https://duckduckgo.com/?q=reading+text+file+in+c%2B%2B
Richard MacCutchan 19-Feb-15 4:20am    
That's a solution.

1 solution

You may use the std::getline[^] function, for the purpose, for instance, the following program tries to do it with the "foo.txt" file
C++
int main()
{
  ifstream ifs("foo.txt");
  while (ifs.good())
  {
    string line;
    getline(ifs, line);
    for (int n = 0; n < line.length(); ++n)
    {
      char c = line[n];
      if ( isalpha(c) )
        PrintCharacter(c);
      else
        cout << c;
    }
    cout << endl;
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900