473,320 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

copy file in an array

2
hello
i am new to C++ and need your help in this code.

i am trying to copy a text file in an array of string a[100] with the getline function but same is not working. below is my code.

#include<iostream>
#include<fstream>
#include<string>

using namespace std;
//template<class T>
//struct b {
//char a[255];
//};


void main()

{
string a[100];
//struct b lines[100];
ifstream input;
input.open("c:\file2.txt");
int i=0;

if(!input)
cout<<"file not opened";
else
cout<<"file opened successfully"<<endl;


while(input)
{
input.getline(a[i],255,"\n");
i++;
}
cout<<lines[i];

thanjs and regards
Oct 12 '06 #1
4 3511
while(input)
{
input.getline(a[i],255,"\n");
i++;
}
What error are you getting? Is it an EndofFileException?

Not sure if input is a boolean, but if it is, your while loop will keep going after the file has run out of lines and produce an exception.
Oct 12 '06 #2
Also, I don't see where the array "lines" is declared.
Oct 12 '06 #3
mungur
2
i am getting the following errors
error C2664: 'class std::basic_istream<char,struct std::char_traits<char> > &__thiscall std::basic_istream<char,struct std::char_traits<char> >::getline(char *,int,char)' : cannot convert parameter 1 from 'class std::basic_
string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char *
at line
input.getline(a[i],255,"\n");
Oct 14 '06 #4
spanky
2
i am getting the following errors
error C2664: 'class std::basic_istream<char,struct std::char_traits<char> > &__thiscall std::basic_istream<char,struct std::char_traits<char> >::getline(char *,int,char)' : cannot convert parameter 1 from 'class std::basic_
string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char *
at line
input.getline(a[i],255,"\n");
Try and use the links used in the following source code.


1: #include <iostream.h>
2: #include <string.h>
3:
4: int main()
5: {
6: char stringOne80];
7: char stringTwo80];
8:
9: stringOne0]='\0';
10: stringTwo0]='\0';
11:
12: cout << "String One: " << stringOne << endl;
13: cout << "String Two: " << stringTwo << endl;
14:
15: cout << "Enter a string: ";
16: cin.getline(stringOne,80);
17:
18: cout << "\nString One: " << stringOne << endl;
19: cout << "String Two: " << stringTwo << endl;
20:
21: cout << "copying..." << endl;
22: strcpy(stringTwo,stringOne);
23:
24: cout << "\nString One: " << stringOne << endl;
25: cout << "String Two: " << stringTwo << endl;
26: cout << "\nDone " << endl;
27: return 0;
28: }
Oct 14 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

30
by: franky.backeljauw | last post by:
Hello, I am wondering which of these two methods is the fastest: std::copy, which is included in the standard library, or a manually written pointer copy? Do any of you have any experience with...
4
by: Venkat | last post by:
Hi All, I need to copy strings from a single dimensional array to a double dimensional array. Here is my program. #include <stdio.h> #include <stdlib.h>
4
by: fperfect13 | last post by:
Hi, I wanted to perform a deep copy of an array. Searching on google I ran into different opinions : C# Interview Questions (http://blogs.wwwcoder.com/tsvmadhav/archive/2005/04/08/2882.aspx)...
15
by: Kueishiong Tu | last post by:
How do I copy the content of a string in one encoding (in my case big5) to a char array (unmanaged) of the same encoding? I try the following String line = S"123æ°´æ³¥"; char buffer; ...
5
by: DraguVaso | last post by:
Hi, I'm looking for a way to Copy and Paste Files to the clipboard. I found a lot of articles to copy pieces of text and bitmaps etc, but nog whole files. Whay I need is like you have in...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
3
by: ShuchiTandon | last post by:
Hi all, i m trying to read from a file and then copy it into an array...my code is as follow..it runs fine but i cant understand y it doesnt show me any output?? here is my code... using...
0
by: Favre Fan | last post by:
Can anyone help me with the array.copy? I have an array coming in from a text file. Info is being read in with my str() string array I then want to copy that array from the third element to the...
2
by: susinthaa | last post by:
Hi, How to copy an array to a file? I tried the File :: copy, But the array is not copying to the file. @susi=$telnet->cmd("logtail"); $newfile = "$movie/$song/$file"; copy(@susi,$newfile)...
3
by: Immortal_Nephi | last post by:
Sometimes, unsigned char array is located in the file scope. You define A Object and B Object. A Object and B Object need to share unsigned char array. They are very different object. They are...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.