5 Replies - 2523 Views - Last Post: 02 November 2010 - 11:45 AM Rate Topic: -----

#1 Barthoid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 27-October 10

Creating a standard shift cipher

Posted 02 November 2010 - 09:29 AM

can anybody help me with this I want to create a simple shift cipher, but when I build the application it gives me an error C3861 'getlin': identifier not found, is it because i need to declare the get line in a header file.
 
#include <cstdlib>
#include <iostream> 
#include <fstream>

using namespace std;

int main(int argc, char *argv[]){
    
    string line = "";
    int lineLength = 0;
    int shiftValue = 0;
    int *asciiValue; // <- Problem1
    char *cipherLine; // <- Problem 2
    ifstream plainText ("plain.txt");
    ofstream cipherText ("cipher.txt");
   
    cout << "Please enter a shift value: ";
    cin >> shiftValue;
 
    while (!plainText.eof()){
    
    getline (plainText, line);*
        lineLength = line.length() - 1;  
     // <- To add, Marker 1->
     asciiValue = new int[lineLength+1];
     cipherLine = new char[lineLength+1];
    for (int i=0; i<=lineLength; i++){
        asciiValue[i] = (int)line[i]; 
        asciiValue[i] += shiftValue;
        cipherLine[i] = (char)asciiValue[i];
        cipherText << cipherLine[i];  
        }   
        // <- To add, Marker 2 ->
        delete cipherLine;
        delete asciiValue;
    cipherText << endl << endl;
    }
    
   cin.get(); // <- Warning 1
    return EXIT_SUCCESS;
}

This post has been edited by JackOfAllTrades: 02 November 2010 - 10:02 AM
Reason for edit:: Fixed code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Creating a standard shift cipher

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,441
  • Joined: 23-August 08

Re: Creating a standard shift cipher

Posted 02 November 2010 - 10:03 AM

Copy and paste your errors EXACTLY as they appear.
Was This Post Helpful? 0
  • +
  • -

#3 jimblumberg  Icon User is offline

  • member icon


Reputation: 3993
  • View blog
  • Posts: 12,323
  • Joined: 25-December 09

Re: Creating a standard shift cipher

Posted 02 November 2010 - 10:03 AM

Please use [ code] code blocks [/code]

Please post the entire error messages.


Jim
Was This Post Helpful? 0
  • +
  • -

#4 Djabby  Icon User is offline

  • D.I.C Head

Reputation: 37
  • View blog
  • Posts: 131
  • Joined: 02-November 10

Re: Creating a standard shift cipher

Posted 02 November 2010 - 10:10 AM

View PostBarthoid, on 02 November 2010 - 08:29 AM, said:

    getline (plainText, line);*
        lineLength = line.length() - 1;  
    ...

    delete cipherLine;
    delete asciiValue;



Few corrections:
First, the * after the getline row seems odd.
Second: You delete arrays not via delete, but via delete[]

This post has been edited by Djabby: 02 November 2010 - 10:10 AM

Was This Post Helpful? 0
  • +
  • -

#5 Barthoid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 27-October 10

Re: Creating a standard shift cipher

Posted 02 November 2010 - 11:38 AM

The* was a typo when i copied the code across
#include <cstdlib>
#include <iostream> 
#include <fstream>

using namespace std;

int main(int argc, char *argv[]){
    
    string line = "";
    int lineLength = 0;
    int shiftValue = 0;
    int *asciiValue; // <- Problem1
    char *cipherLine; // <- Problem 2
    ifstream plainText ("plain.txt");
    ofstream cipherText ("cipher.txt");
   
    cout << "Please enter a shift value: ";
    cin >> shiftValue;
 
    while (!plainText.eof()){
    
    getline(plainText, line);
        lineLength = line.length() - 1;  
     // <- To add, Marker 1->
     asciiValue = new int[lineLength+1];
     cipherLine = new char[lineLength+1];


    for (int i=0; i<=lineLength; i++){
        asciiValue[i] = (int)line[i]; 
        asciiValue[i] += shiftValue;
        cipherLine[i] = (char)asciiValue[i];
        cipherText << cipherLine[i];  
        }   
        // <- To add, Marker 2 ->
        delete cipherLine;
        delete asciiValue;
    cipherText << endl << endl;
    }


the actual errors are:
Error	1	error C3861: 'getline': identifier not found	g:\c++\cipher text\cipher text\text.cpp	22	1	cipher text
	                                 2	IntelliSense: identifier "getline" is undefined	g:\c++\cipher text\cipher text\text.cpp	22	5	cipher text


Was This Post Helpful? 0
  • +
  • -

#6 Djabby  Icon User is offline

  • D.I.C Head

Reputation: 37
  • View blog
  • Posts: 131
  • Joined: 02-November 10

Re: Creating a standard shift cipher

Posted 02 November 2010 - 11:45 AM

Know what you have to include: Link

The function getline is defined in <string> which you haven't included yet. Just do:

#include <string>


Though I am surprised that string line = ""; works.

Edit:
There seems to be a declaration of std::string in <iostream> but that doesn't mean that the whole <string>-library is included too.

This post has been edited by Djabby: 02 November 2010 - 11:49 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1