I dont know how good you are going to undestand me:
I made an encryption program. It uses space between 2 letteres. Now I want to use the generated string and read every word at a time and convert it to a letter.
Here is the code:
// decript.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <algorithm>
#include <iterator>
using namespace std;
Use code tags, please - read the FAQ if you don't konw what they are
Your variable str is an array of two characters
You are reading in a single character from the user, storing it at the second position of your array, then you assign this character to the variable line
Your call to strtok will not compile, becuase strtok expects a character string as first argument, not a single character (how would it split up a single character)
Why not use std::string instead of char ?
More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf
Premature optimization is the root of all evil --Donald E. Knuth
Sorry, but I'll have to do mare reasearch regarding std::string ( what is the difference?).
std::string is a class wrapping a dynamic char array. In addition to handling all the tricky memory management internally so that you don't have to, it provides numerous operators which make string operations much more intuitive. Plus it removes the possibility of overwriting the array bounds that you get with fixed-size arrays.
The one thing it doesn't play well with is strtok. You can get equivalent functionality out of it with other methods, but since strtok changes the string in-place by inserting NULLs, you can't use it directly.
@Lindley
Thanks for your quick message, I found out that std::string doesnt work with strtok.......Any example of conversion(I have no idea) ???
This works:
Bookmarks