C++ :: Transform TXT File To Char Vector?
Aug 17, 2013
I need to transform a .txt file to a char vector, but how to do it. as much as I could until now been transformed into vector string.
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
[Code].....
View 7 Replies
ADVERTISEMENT
Feb 8, 2015
I have had quite a head spinner on trying to transform a string into a char. I've been trying to do this for the project below.
[URL] ....
std::string str = "string";
const char* chr = str.c_str();
cout << *chr << endl;
Above is the code I have tried using and it stores data under *chr, it however only stores one letter rather than the entire word like for example string.
View 2 Replies
View Related
Oct 29, 2014
Code:
cout<<"Enter Filename for input e.g(inp1.txt .... inp10.txt):"<<flush;
cin>>filename;
ifstream inpfile;
inpfile.open(filename,ios::in);
if(inpfile.is_open())
[Code] .....
View 8 Replies
View Related
Dec 1, 2013
This seamed as a simple thing but i am getting something i did not expect: Example:
Code:
vector<char> StrJoin(SubjSeq.size()+ QuerySeq.size());
cout << StrJoin.size()<<"
"; // size x
StrJoin.insert( StrJoin.begin(), QuerySeq.begin(), QuerySeq.end() );
StrJoin.insert( StrJoin.begin(), SubjSeq.begin(), SubjSeq.end() );
cout << StrJoin.size()<<"
"; // x*2
All structures are vector<char>. when i do the above my characters form Query and Subject are copied in my new vector called StrJoin but the size of that vector is twice the size then it should be.
View 3 Replies
View Related
Jun 8, 2013
let say
char temp[8][8];
and you want to make vector of this char
vector<????> boardVec;
View 2 Replies
View Related
Feb 3, 2013
I was working on a program which compares sequences of characters, counts the differences between them, and displays them. I had the sequence inputted as a string (into a vector so any number of sequences could be chosen), and then, the way I tried to check the strings for differences, was by converting the string to a (multidimensional) vector of chars:
vector< vector<char> > sequencesC;
for (int a = 0; a < sequenceCount; a++) {
cout << "
Enter sequence " << a+1 <<" name: ";
cin >> sequenceNames[a];
cout << "
[code]....
However, it crashes (as shown above) when I try to set, by a for loop, every char of a multidimensional vector (sequencesC) to the same char of the data vector. Is there any way I can convert the string to a char vector?
View 7 Replies
View Related
Feb 3, 2014
I've got something I'm trying to accomplish, but crashes my program.
I've got my server and client code.
Having the client send a message they type (char Chat[1024]) And the server receiving the chat (char recv_chat[1024]) only to send it to all connected clients again. Which the server sends the recv_chat.
The client receives it (char recv_chat[1024]). This works, and the client gets the right info. However, I'm trying to store it using a vector. I'm sure I've tried any way possible.
Client storing vector pseudo-code:
vector<char*> SaveChat;
int main () {
while (true) {
if (newClientConnected) {
[Code]....
This doesn't work, and crashes my application. I've tried changing the vector to string, const char*, basically anything I can with no avail.
View 8 Replies
View Related
Aug 26, 2013
I was assigned to print a linked list but as a vector of char (I cannot use the normal string type) , this is what I have:
char* List::asString(){
Node* ite = new Node();
ite= first;//ite is like an iterator of the list
for(int i=0; i<sizeOfList; ++i){//sizeOfList is the total of node of the list
[Code] ....
But when I print that, I get a bunch of weird symbols...
View 7 Replies
View Related
Apr 19, 2012
The below code is giving me segment fault during delete [] (*iter) sometimes. Is it not the proper way to delete the vector with char *
Code:
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<char*> nameList;
for (int i=0;i<1000;++i)
[Code] ....
View 7 Replies
View Related
Jun 9, 2013
I want to save the char[8][8] // fixed size 2 dimension array
to a vector
such as
vector<?????> temp;
is there anyway to approach this?
View 4 Replies
View Related
Apr 14, 2015
This is how my .xml page looks in a web browser. Is there a way to transform my .xml file into .txt file so that the text file would look like this?
View 14 Replies
View Related
Jun 7, 2012
I have a cpp app that reads in a number of files and writes revised output. The app doesn't seem to be able to open a file with a ' in the file name, such as,
N,N'-dimethylethylenediamine.mol
This is the function that opens the file :
Code:
// opens mol file, reads in rows to string vector and returns vector
vector<string> get_mol_file(string& filePath) {
vector<string> mol_file;
string new_mol_line;
// create an input stream and open the mol file
ifstream read_mol_input;
read_mol_input.open( filePath.c_str() );
[Code] ....
The path to the file is passed as a cpp string and the c version is used to open the file. Do I need to handle this as a special case? It is possible that there could be " as well, parenthesis, etc.
View 9 Replies
View Related
Jun 18, 2014
I am trying to transform seconds into HH:MM:SS. I thought it would be easy using the TimeSpan functions however my hours exceed 24 hours now and then therefor it is not viable for use.
private string getFormattedTimeFromSecond(double second)
{
TimeSpan t = TimeSpan.FromSeconds( second );
string answer = string.Format("{0:D2}h:{1:D2}m:{2:D2}s",
t.Hours,
t.Minutes,
t.Seconds);
}
This is what I have tried, however it does not like it much when hours exceed 24.
View 6 Replies
View Related
Jul 5, 2013
I am having problems doing the fourier transform:
[URL] .....
My code is:
esc = 2;
maxi = 0;
fu = 500;
fo = 3000;
for (f=fu;f<=fo;f + esc) {
[Code] ....
Don't worry about the exp and complex numbers because they work correctly. N is the number of samples of the input (2500). Esc is the difference between different frequences. So the samples of the output are (1250).
View 3 Replies
View Related
Jun 8, 2013
I have a problem concerning transforming int array into bmp image. I wanted to add a post in this topic: [URL] .... , but unfortunately it is closed. Actually I have a question concerning the code written by Duoas. I have a function which takes values from the file and I want to convert it into bmp with the use of Duoas code. I do it like that(it's Duoas code + my load and main function) Is it something wrong with how I do it or it's rather sth wrong with the file.
It compiles without errors but when I run it: core dumped.
According to gdb debugger problem is here: double hue = (intarray[ row - 1 ][ col ] - min_value) * granularity; programs stops, segmentation fault ...
#ifndef INTARRAY2BMP_HPP
#define INTARRAY2BMP_HPP
#include <fstream>
#include <iostream>
#include <string>
[Code] ....
View 2 Replies
View Related
Jun 9, 2013
i am looking for a verified code in simple c, for generating fft of an input image (.jpg). the output can be a text file including fft coefficients.can you recommend me any source except open-cv?
View 6 Replies
View Related
Aug 4, 2014
I was wondering if its possible to change the color of the anchor point in the transform tool.
Is this possible? Sometimes I'll move it and it takes forever to find it again on a dark image. The actual image of the cross hairs must live in the application contents somewhere? Or its made by script. After a quick search of "transform" I found this file.. Not exactly sure what I'm looking at inside but it appears to be c++ code? [URL] ....
SCREEN GRAB: [URL] ....
FILE: [URL] ....
View 1 Replies
View Related
Aug 25, 2014
I have this code which performs the analysis part of discrete wavelet transform. It works pretty well. However, I wish to reduce the time that it consumes even further. I did use reserve() and it worked upto few msec.
int rows = signal.size();
int cols = signal[0].size();
int cols_lp1 =(int) ceil( (double) cols / 2);
vector<vector<double> > lp_dn1(rows, vector<double>(cols_lp1));
vector<double> temp_row;
temp_row.reserve(512);
[Code] ....
View 5 Replies
View Related
Aug 23, 2013
I found this piece code on the following site:
[URL]
I predicted the outcome as being 01230 as I thought the prefix decrement operator on iterator ce would prevent the final element of the list from being transformed.
I was wrong, the correct output is 01234.
So, I removed the decrement prefix and ran the test again, expecting a different result. It wasn't! The result was still 01234.
Only when I decremented ce twice did I get the result I initially expected, 01230.
why the first decrement of ce appears to have no effect?
#include <algorithm>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <cstdio>
int main() {
typedef std::list<int> L;
[code]....
View 2 Replies
View Related
Oct 25, 2014
I need to transform a local variable into a global variable so I can use it in one of my functions. I thought about passing the value as a parameter to this function but I can do this since the function is called inside the while loop and this variable counts how many times the while loop does (so the final value is outside the loop). Example to visualize better:
Code:
while(condition) {
function(parameter1, parameter2);
count = count + 1;
}
printf("%d
", count);
So, I need to transform the final value of "count" into a global variable. Can I do this?
View 5 Replies
View Related
Mar 14, 2013
Can we open a file in c++ using a variable(either character or int)?
View 1 Replies
View Related
Jan 20, 2014
i found a lot about how to convert int to const char * but non of them explain correctly or sometimes dont even work.
Here is my code:
#include <stdio.h>
#include <cstdlib>
using namespace std;
int main () {
int i =0;
char c1 =0;
char c2 =0;
[code]....
View 15 Replies
View Related
Jun 3, 2014
I want to remove some character in my file. too i want to replace some char to another. I know the easiest way for this job is we write final text in file. i mean we first produce sightly text then write it in file . I don't want use of temporary string.
View 3 Replies
View Related
Feb 21, 2015
I have a specific byte (that is unsigned char) array, that I need to find in a very big file (2GB or so), currently I'm using:
size_t fsFind(FILE* device, byte* data, size_t size) {
int SIZE = (1024 > size) ? 1024 : size;
byte buffer[SIZE];
int pos = 0;
int loc = ftell(device);
[Code] ....
Which seems to find proper result on first use, but on subsequent searches it seems to find invalid positions, is there something I'm doing wrong, or is there a better way?
View 6 Replies
View Related
Oct 17, 2014
I have a project which is about linked lists in the order of: a Story is made of Paragraphs which is made of Sentences which is made of Words. We must treat Words specifically as character arrays, not strings. So I need to read in a story from a text file and make Words by finding the first whitespace/punctuation(everything before the whitespace up until the whitespace or punctuation is the Word), all the Words up to the punctuation are a Sentence (Sentence is a linked list of Words), Paragraph is all the Sentences up until an empty line, and a Story is all the Paragraphs. So I know doing this will let me take a line and put it into a character array:
char charArray[25]; //we are allowed to assume a word won't be longer than 25 characters
int i = 0;
ifstream myFile(fileName.c_str());
if(myFile.is_open()){
[Code].....
I suppose I could look at charArray[i] and if it is ws or punctuation then make the Word = charArray[i-1], but is there an if statement I could do that would prevent the ws or punctuation from being read into charArray in the first place? Because a problem I see with the charArray[i-1] method already is that "This is a story." would get put into the array as Thisisastory. and thus I'd be unable to break up at a space.
So to summarize: I want to read in a text file character by character into a char array, which I can set to length 25 due to context of the project. I want to read in each character and at a whitespace or punctuation, I want to take everything already in charArray and feed that into a Word object constructor (the next Word gets linked to the previous Word, and at a punctuation all the Words linked together become one Sentence, and all the Sentences linked before an empty line become a Paragraph, etc). So how can I get charArray to be only characters in a word, then after the word being read-in ends, charArray resets to empty, and then is populated by the next word and so on.
View 2 Replies
View Related
Feb 25, 2014
I am trying to read strings to an char array from an .exe file and then i would check some of the strings, but the problem is that the only thing that is read from the file is the first string (MZ) and an 'square' that is some incorrect character. I am using fread to read from the file. Here is my code:
FILE * pFile;
long lSize;
char * buffer;
size_t result;
pFile = fopen("my_file.exe", "rb");
if( pFile == NULL) exit(1);
fseek(pFile,0, SEEK_END);
[Code] ....
(I want to read the whole file, its not that big)...
View 14 Replies
View Related